@player-tools/fluent 0.13.0--canary.221.5662

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/cjs/index.cjs +2257 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.legacy-esm.js +2143 -0
  4. package/dist/index.mjs +2143 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +36 -0
  7. package/src/core/base-builder/__tests__/fluent-builder-base.test.ts +2257 -0
  8. package/src/core/base-builder/__tests__/id-generator.test.ts +658 -0
  9. package/src/core/base-builder/__tests__/registry.test.ts +411 -0
  10. package/src/core/base-builder/__tests__/switch.test.ts +501 -0
  11. package/src/core/base-builder/__tests__/template.test.ts +449 -0
  12. package/src/core/base-builder/__tests__/value-extraction.test.ts +200 -0
  13. package/src/core/base-builder/conditional/index.ts +64 -0
  14. package/src/core/base-builder/context.ts +151 -0
  15. package/src/core/base-builder/fluent-builder-base.ts +261 -0
  16. package/src/core/base-builder/guards.ts +137 -0
  17. package/src/core/base-builder/id/generator.ts +286 -0
  18. package/src/core/base-builder/id/registry.ts +152 -0
  19. package/src/core/base-builder/index.ts +60 -0
  20. package/src/core/base-builder/resolution/path-resolver.ts +108 -0
  21. package/src/core/base-builder/resolution/pipeline.ts +96 -0
  22. package/src/core/base-builder/resolution/steps/asset-id.ts +77 -0
  23. package/src/core/base-builder/resolution/steps/asset-wrappers.ts +64 -0
  24. package/src/core/base-builder/resolution/steps/builders.ts +85 -0
  25. package/src/core/base-builder/resolution/steps/mixed-arrays.ts +117 -0
  26. package/src/core/base-builder/resolution/steps/static-values.ts +35 -0
  27. package/src/core/base-builder/resolution/steps/switches.ts +63 -0
  28. package/src/core/base-builder/resolution/steps/templates.ts +30 -0
  29. package/src/core/base-builder/resolution/value-resolver.ts +308 -0
  30. package/src/core/base-builder/storage/auxiliary-storage.ts +82 -0
  31. package/src/core/base-builder/storage/value-storage.ts +280 -0
  32. package/src/core/base-builder/types.ts +184 -0
  33. package/src/core/base-builder/utils.ts +10 -0
  34. package/src/core/flow/__tests__/index.test.ts +292 -0
  35. package/src/core/flow/index.ts +141 -0
  36. package/src/core/index.ts +8 -0
  37. package/src/core/mocks/generated/action.builder.ts +109 -0
  38. package/src/core/mocks/generated/choice.builder.ts +161 -0
  39. package/src/core/mocks/generated/choiceItem.builder.ts +133 -0
  40. package/src/core/mocks/generated/collection.builder.ts +117 -0
  41. package/src/core/mocks/generated/index.ts +7 -0
  42. package/src/core/mocks/generated/info.builder.ts +80 -0
  43. package/src/core/mocks/generated/input.builder.ts +75 -0
  44. package/src/core/mocks/generated/text.builder.ts +63 -0
  45. package/src/core/mocks/index.ts +1 -0
  46. package/src/core/mocks/types/action.ts +92 -0
  47. package/src/core/mocks/types/choice.ts +129 -0
  48. package/src/core/mocks/types/collection.ts +140 -0
  49. package/src/core/mocks/types/info.ts +7 -0
  50. package/src/core/mocks/types/input.ts +7 -0
  51. package/src/core/mocks/types/text.ts +5 -0
  52. package/src/core/schema/__tests__/index.test.ts +127 -0
  53. package/src/core/schema/index.ts +195 -0
  54. package/src/core/schema/types.ts +7 -0
  55. package/src/core/switch/__tests__/index.test.ts +156 -0
  56. package/src/core/switch/index.ts +76 -0
  57. package/src/core/tagged-template/README.md +448 -0
  58. package/src/core/tagged-template/__tests__/extract-bindings-from-schema.test.ts +207 -0
  59. package/src/core/tagged-template/__tests__/index.test.ts +190 -0
  60. package/src/core/tagged-template/__tests__/schema-std-integration.test.ts +580 -0
  61. package/src/core/tagged-template/binding.ts +95 -0
  62. package/src/core/tagged-template/expression.ts +92 -0
  63. package/src/core/tagged-template/extract-bindings-from-schema.ts +120 -0
  64. package/src/core/tagged-template/index.ts +5 -0
  65. package/src/core/tagged-template/std.ts +472 -0
  66. package/src/core/tagged-template/types.ts +123 -0
  67. package/src/core/template/__tests__/index.test.ts +380 -0
  68. package/src/core/template/index.ts +191 -0
  69. package/src/core/utils/index.ts +160 -0
  70. package/src/fp/README.md +411 -0
  71. package/src/fp/__tests__/index.test.ts +1178 -0
  72. package/src/fp/index.ts +386 -0
  73. package/src/gen/common.ts +2 -0
  74. package/src/gen/plugin.mjs +315 -0
  75. package/src/index.ts +5 -0
  76. package/src/types.ts +203 -0
  77. package/types/core/base-builder/conditional/index.d.ts +21 -0
  78. package/types/core/base-builder/context.d.ts +39 -0
  79. package/types/core/base-builder/fluent-builder-base.d.ts +132 -0
  80. package/types/core/base-builder/guards.d.ts +58 -0
  81. package/types/core/base-builder/id/generator.d.ts +69 -0
  82. package/types/core/base-builder/id/registry.d.ts +93 -0
  83. package/types/core/base-builder/index.d.ts +8 -0
  84. package/types/core/base-builder/resolution/path-resolver.d.ts +15 -0
  85. package/types/core/base-builder/resolution/pipeline.d.ts +25 -0
  86. package/types/core/base-builder/resolution/steps/asset-id.d.ts +14 -0
  87. package/types/core/base-builder/resolution/steps/asset-wrappers.d.ts +14 -0
  88. package/types/core/base-builder/resolution/steps/builders.d.ts +14 -0
  89. package/types/core/base-builder/resolution/steps/mixed-arrays.d.ts +14 -0
  90. package/types/core/base-builder/resolution/steps/static-values.d.ts +14 -0
  91. package/types/core/base-builder/resolution/steps/switches.d.ts +15 -0
  92. package/types/core/base-builder/resolution/steps/templates.d.ts +14 -0
  93. package/types/core/base-builder/resolution/value-resolver.d.ts +37 -0
  94. package/types/core/base-builder/storage/auxiliary-storage.d.ts +50 -0
  95. package/types/core/base-builder/storage/value-storage.d.ts +82 -0
  96. package/types/core/base-builder/types.d.ts +141 -0
  97. package/types/core/base-builder/utils.d.ts +2 -0
  98. package/types/core/flow/index.d.ts +23 -0
  99. package/types/core/index.d.ts +8 -0
  100. package/types/core/mocks/index.d.ts +2 -0
  101. package/types/core/mocks/types/action.d.ts +58 -0
  102. package/types/core/mocks/types/choice.d.ts +95 -0
  103. package/types/core/mocks/types/collection.d.ts +102 -0
  104. package/types/core/mocks/types/info.d.ts +7 -0
  105. package/types/core/mocks/types/input.d.ts +7 -0
  106. package/types/core/mocks/types/text.d.ts +5 -0
  107. package/types/core/schema/index.d.ts +34 -0
  108. package/types/core/schema/types.d.ts +5 -0
  109. package/types/core/switch/index.d.ts +21 -0
  110. package/types/core/tagged-template/binding.d.ts +19 -0
  111. package/types/core/tagged-template/expression.d.ts +11 -0
  112. package/types/core/tagged-template/extract-bindings-from-schema.d.ts +7 -0
  113. package/types/core/tagged-template/index.d.ts +6 -0
  114. package/types/core/tagged-template/std.d.ts +174 -0
  115. package/types/core/tagged-template/types.d.ts +69 -0
  116. package/types/core/template/index.d.ts +97 -0
  117. package/types/core/utils/index.d.ts +47 -0
  118. package/types/fp/index.d.ts +149 -0
  119. package/types/gen/common.d.ts +3 -0
  120. package/types/index.d.ts +3 -0
  121. package/types/types.d.ts +163 -0
@@ -0,0 +1,109 @@
1
+ import type { ActionAsset, ActionMetaData } from "../types/action.js";
2
+ import type { Asset, AssetWrapper } from "@player-ui/types";
3
+ import { type FluentBuilder, type BaseBuildContext, FluentBuilderBase, createInspectMethod } from "../../../gen/common.js";
4
+ import type { TaggedTemplateValue } from "@player-tools/fluent";
5
+
6
+ export interface ActionAssetBuilderMethods<AnyAsset extends Asset<string> = Asset<string>> {
7
+ /** The transition value of the action in the state machine */
8
+ withValue(value: string | TaggedTemplateValue<string>): ActionAssetBuilder<AnyAsset>;
9
+ /** A text-like asset for the action's label */
10
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ActionAssetBuilder<AnyAsset>;
11
+ /** An optional expression to execute before transitioning */
12
+ withExp(value: string | TaggedTemplateValue<string> | Array<string | TaggedTemplateValue<string>>): ActionAssetBuilder<AnyAsset>;
13
+ /** An optional string that describes the action for screen-readers */
14
+ withAccessibility(value: string | TaggedTemplateValue<string>): ActionAssetBuilder<AnyAsset>;
15
+ /** An optional confirmation dialog to show before executing the action */
16
+ withConfirmation(value: { message: string | TaggedTemplateValue<string>; affirmativeLabel: string | TaggedTemplateValue<string>; negativeLabel?: string | TaggedTemplateValue<string> }): ActionAssetBuilder<AnyAsset>;
17
+ /** Additional optional data to assist with the action interactions on the page */
18
+ withMetaData(value: ActionMetaData | FluentBuilder<ActionMetaData, BaseBuildContext>): ActionAssetBuilder<AnyAsset>;
19
+ /** Triggers the listed bindings to be validated */
20
+ withValidate(value: string | TaggedTemplateValue<string> | Array<string | TaggedTemplateValue<string>>): ActionAssetBuilder<AnyAsset>;
21
+ /** Each asset requires a unique id per view */
22
+ withId(value: string | TaggedTemplateValue<string>): ActionAssetBuilder<AnyAsset>;
23
+ /** The asset type determines the semantics of how a user interacts with a page */
24
+ withType(value: "action"): ActionAssetBuilder<AnyAsset>;
25
+ }
26
+
27
+ /**
28
+ * A builder for ActionAsset
29
+ */
30
+ export class ActionAssetBuilder<AnyAsset extends Asset<string> = Asset<string>> extends FluentBuilderBase<ActionAsset<AnyAsset>> implements ActionAssetBuilderMethods<AnyAsset>, FluentBuilder<ActionAsset<AnyAsset>, BaseBuildContext> {
31
+ private static readonly defaults: Record<string, unknown> = { id: "", type: "action" };
32
+
33
+ /** The transition value of the action in the state machine */
34
+ withValue(value: string | TaggedTemplateValue<string>): ActionAssetBuilder<AnyAsset> {
35
+ return this.set("value", value);
36
+ }
37
+
38
+ /** A text-like asset for the action's label */
39
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ActionAssetBuilder<AnyAsset> {
40
+ const extractedValue = { asset: value };
41
+
42
+ return this.set("label", extractedValue);
43
+ }
44
+
45
+ /** An optional expression to execute before transitioning */
46
+ withExp(value: string | TaggedTemplateValue<string> | Array<string | TaggedTemplateValue<string>>): ActionAssetBuilder<AnyAsset> {
47
+ return this.set("exp", value);
48
+ }
49
+
50
+ /** An optional string that describes the action for screen-readers */
51
+ withAccessibility(value: string | TaggedTemplateValue<string>): ActionAssetBuilder<AnyAsset> {
52
+ return this.set("accessibility", value);
53
+ }
54
+
55
+ /** An optional confirmation dialog to show before executing the action */
56
+ withConfirmation(value: { message: string | TaggedTemplateValue<string>; affirmativeLabel: string | TaggedTemplateValue<string>; negativeLabel?: string | TaggedTemplateValue<string> }): ActionAssetBuilder<AnyAsset> {
57
+ return this.set("confirmation", value);
58
+ }
59
+
60
+ /** Additional optional data to assist with the action interactions on the page */
61
+ withMetaData(value: ActionMetaData | FluentBuilder<ActionMetaData, BaseBuildContext>): ActionAssetBuilder<AnyAsset> {
62
+ return this.set("metaData", value);
63
+ }
64
+
65
+ /** Triggers the listed bindings to be validated */
66
+ withValidate(value: string | TaggedTemplateValue<string> | Array<string | TaggedTemplateValue<string>>): ActionAssetBuilder<AnyAsset> {
67
+ return this.set("validate", value);
68
+ }
69
+
70
+ /** Each asset requires a unique id per view */
71
+ withId(value: string | TaggedTemplateValue<string>): ActionAssetBuilder<AnyAsset> {
72
+ return this.set("id", value);
73
+ }
74
+
75
+ /** The asset type determines the semantics of how a user interacts with a page */
76
+ withType(value: "action"): ActionAssetBuilder<AnyAsset> {
77
+ return this.set("type", value);
78
+ }
79
+
80
+ /**
81
+ * Set additional properties with dynamic keys
82
+ * @param props - Object with dynamic properties
83
+ */
84
+ withAdditionalProperties(props: Record<string, unknown>): ActionAssetBuilder<AnyAsset> {
85
+ Object.assign(this.values, props);
86
+ return this as ActionAssetBuilder<AnyAsset>;
87
+ }
88
+
89
+ /**
90
+ * Builds the final ActionAsset object
91
+ * @param context - Optional build context for nested builders
92
+ */
93
+ build(context?: BaseBuildContext): ActionAsset<AnyAsset> {
94
+ return this.buildWithDefaults(ActionAssetBuilder.defaults, context);
95
+ }
96
+
97
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
98
+ return createInspectMethod("ActionAssetBuilder", this.values);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Creates a new ActionAsset builder
104
+ * @param initial Optional initial values
105
+ * @returns A fluent builder for ActionAsset
106
+ */
107
+ export function action<AnyAsset extends Asset<string> = Asset<string>>(initial?: Partial<ActionAsset<AnyAsset>>): ActionAssetBuilder<AnyAsset> {
108
+ return new ActionAssetBuilder<AnyAsset>(initial);
109
+ }
@@ -0,0 +1,161 @@
1
+ import type { ChoiceAsset, ChoiceItem, ChoiceInputModifier, ChoiceItemMetadata, ChoiceModifier, ChoiceMetaData } from "../types/choice.js";
2
+ import type { Asset, AssetWrapper } from "@player-ui/types";
3
+ import { type FluentBuilder, type BaseBuildContext, FluentBuilderBase, createInspectMethod } from "../../../gen/common.js";
4
+ import type { TaggedTemplateValue } from "@player-tools/fluent";
5
+
6
+ export interface ChoiceAssetBuilderMethods<AnyAsset extends Asset<string> = Asset<string>> {
7
+ /** The binding used to keep track of the selected Choice */
8
+ withBinding(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset>;
9
+ /** The choiceItems used as options */
10
+ withChoices(value: Array<ChoiceItem<AnyAsset> | FluentBuilder<ChoiceItem<AnyAsset>, BaseBuildContext>>): ChoiceAssetBuilder<AnyAsset>;
11
+ /** The label describing the choice field. */
12
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
13
+ /** choice help providing additional info that could be helpful */
14
+ withHelp(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
15
+ /** choice note */
16
+ withNote(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
17
+ /** placeholder string to show by default for the choice */
18
+ withPlaceholder(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset>;
19
+ /** any accessibility text to be added as an aria label. */
20
+ withAccessibility(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset>;
21
+ /** The info that appears underneath the choice */
22
+ withAdditionalInfo(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
23
+ /** The resulting Text that appears underneath the choice */
24
+ withResultText(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
25
+ withModifiers(value: Array<ChoiceInputModifier | ChoiceModifier>): ChoiceAssetBuilder<AnyAsset>;
26
+ /** Additional metaData for the Choice */
27
+ withMetaData(value: ChoiceMetaData | FluentBuilder<ChoiceMetaData, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
28
+ /** The main action associated with choices */
29
+ withAction(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
30
+ /** The main image associated with choices */
31
+ withImage(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset>;
32
+ /** Each asset requires a unique id per view */
33
+ withId(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset>;
34
+ /** The asset type determines the semantics of how a user interacts with a page */
35
+ withType(value: "choice"): ChoiceAssetBuilder<AnyAsset>;
36
+ }
37
+
38
+ /**
39
+ * A builder for ChoiceAsset
40
+ */
41
+ export class ChoiceAssetBuilder<AnyAsset extends Asset<string> = Asset<string>> extends FluentBuilderBase<ChoiceAsset<AnyAsset>> implements ChoiceAssetBuilderMethods<AnyAsset>, FluentBuilder<ChoiceAsset<AnyAsset>, BaseBuildContext> {
42
+ private static readonly defaults: Record<string, unknown> = { binding: "", id: "", type: "choice" };
43
+
44
+ /** The binding used to keep track of the selected Choice */
45
+ withBinding(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset> {
46
+ return this.set("binding", value);
47
+ }
48
+
49
+ /** The choiceItems used as options */
50
+ withChoices(value: Array<ChoiceItem<AnyAsset> | FluentBuilder<ChoiceItem<AnyAsset>, BaseBuildContext>>): ChoiceAssetBuilder<AnyAsset> {
51
+ return this.set("choices", value);
52
+ }
53
+
54
+ /** The label describing the choice field. */
55
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
56
+ const extractedValue = { asset: value };
57
+
58
+ return this.set("label", extractedValue);
59
+ }
60
+
61
+ /** choice help providing additional info that could be helpful */
62
+ withHelp(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
63
+ const extractedValue = { asset: value };
64
+
65
+ return this.set("help", extractedValue);
66
+ }
67
+
68
+ /** choice note */
69
+ withNote(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
70
+ const extractedValue = { asset: value };
71
+
72
+ return this.set("note", extractedValue);
73
+ }
74
+
75
+ /** placeholder string to show by default for the choice */
76
+ withPlaceholder(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset> {
77
+ return this.set("placeholder", value);
78
+ }
79
+
80
+ /** any accessibility text to be added as an aria label. */
81
+ withAccessibility(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset> {
82
+ return this.set("accessibility", value);
83
+ }
84
+
85
+ /** The info that appears underneath the choice */
86
+ withAdditionalInfo(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
87
+ const extractedValue = { asset: value };
88
+
89
+ return this.set("additionalInfo", extractedValue);
90
+ }
91
+
92
+ /** The resulting Text that appears underneath the choice */
93
+ withResultText(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
94
+ const extractedValue = { asset: value };
95
+
96
+ return this.set("resultText", extractedValue);
97
+ }
98
+
99
+ withModifiers(value: Array<ChoiceInputModifier | ChoiceModifier>): ChoiceAssetBuilder<AnyAsset> {
100
+ return this.set("modifiers", value);
101
+ }
102
+
103
+ /** Additional metaData for the Choice */
104
+ withMetaData(value: ChoiceMetaData | FluentBuilder<ChoiceMetaData, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
105
+ return this.set("metaData", value);
106
+ }
107
+
108
+ /** The main action associated with choices */
109
+ withAction(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
110
+ const extractedValue = { asset: value };
111
+
112
+ return this.set("action", extractedValue);
113
+ }
114
+
115
+ /** The main image associated with choices */
116
+ withImage(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceAssetBuilder<AnyAsset> {
117
+ const extractedValue = { asset: value };
118
+
119
+ return this.set("image", extractedValue);
120
+ }
121
+
122
+ /** Each asset requires a unique id per view */
123
+ withId(value: string | TaggedTemplateValue<string>): ChoiceAssetBuilder<AnyAsset> {
124
+ return this.set("id", value);
125
+ }
126
+
127
+ /** The asset type determines the semantics of how a user interacts with a page */
128
+ withType(value: "choice"): ChoiceAssetBuilder<AnyAsset> {
129
+ return this.set("type", value);
130
+ }
131
+
132
+ /**
133
+ * Set additional properties with dynamic keys
134
+ * @param props - Object with dynamic properties
135
+ */
136
+ withAdditionalProperties(props: Record<string, unknown>): ChoiceAssetBuilder<AnyAsset> {
137
+ Object.assign(this.values, props);
138
+ return this as ChoiceAssetBuilder<AnyAsset>;
139
+ }
140
+
141
+ /**
142
+ * Builds the final ChoiceAsset object
143
+ * @param context - Optional build context for nested builders
144
+ */
145
+ build(context?: BaseBuildContext): ChoiceAsset<AnyAsset> {
146
+ return this.buildWithDefaults(ChoiceAssetBuilder.defaults, context);
147
+ }
148
+
149
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
150
+ return createInspectMethod("ChoiceAssetBuilder", this.values);
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Creates a new ChoiceAsset builder
156
+ * @param initial Optional initial values
157
+ * @returns A fluent builder for ChoiceAsset
158
+ */
159
+ export function choice<AnyAsset extends Asset<string> = Asset<string>>(initial?: Partial<ChoiceAsset<AnyAsset>>): ChoiceAssetBuilder<AnyAsset> {
160
+ return new ChoiceAssetBuilder<AnyAsset>(initial);
161
+ }
@@ -0,0 +1,133 @@
1
+ import type { ChoiceItem, ChoiceInputModifier, ChoiceItemMetadata } from "../types/choice.js";
2
+ import type { Asset, AssetWrapper } from "@player-ui/types";
3
+ import { type FluentBuilder, type BaseBuildContext, FluentBuilderBase, createInspectMethod } from "../../../gen/common.js";
4
+ import type { TaggedTemplateValue } from "@player-tools/fluent";
5
+
6
+ export interface ChoiceItemBuilderMethods<AnyAsset extends Asset<string> = Asset<string>> {
7
+ /** The id associated with the choice item */
8
+ withId(value: string | TaggedTemplateValue<string>): ChoiceItemBuilder<AnyAsset>;
9
+ /** The id used for replay tests. */
10
+ withAutomationId(value: string | TaggedTemplateValue<string>): ChoiceItemBuilder<AnyAsset>;
11
+ /** The label describing the choice. */
12
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
13
+ /** The icon describing the choice. */
14
+ withIcon(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
15
+ /** The help for the choice. */
16
+ withHelp(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
17
+ /** Support the legacy choiceHelp prop. No storybook docs for this; deprecated in favour of the "help" field. */
18
+ withChoiceHelp(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
19
+ /** The description of the choice. */
20
+ withDescription(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
21
+ /** The footer of the choice. */
22
+ withFooter(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
23
+ /** The value to set when this choice is selected */
24
+ withValue(value: string | number | false | true): ChoiceItemBuilder<AnyAsset>;
25
+ /** The details shown when a user selects the choice item */
26
+ withChoiceDetail(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
27
+ /** Any modifiers for the current item. No storybook docs for this as "readonly" (the only modifier) shouldn't be used anymore. */
28
+ withModifiers(value: Array<ChoiceInputModifier | FluentBuilder<ChoiceInputModifier, BaseBuildContext>>): ChoiceItemBuilder<AnyAsset>;
29
+ /** MetaData for the choiceItem */
30
+ withMetaData(value: ChoiceItemMetadata | FluentBuilder<ChoiceItemMetadata, BaseBuildContext>): ChoiceItemBuilder<AnyAsset>;
31
+ }
32
+
33
+ /**
34
+ * A builder for ChoiceItem
35
+ */
36
+ export class ChoiceItemBuilder<AnyAsset extends Asset<string> = Asset<string>> extends FluentBuilderBase<ChoiceItem<AnyAsset>> implements ChoiceItemBuilderMethods<AnyAsset>, FluentBuilder<ChoiceItem<AnyAsset>, BaseBuildContext> {
37
+ private static readonly defaults: Record<string, unknown> = { id: "" };
38
+
39
+ /** The id associated with the choice item */
40
+ withId(value: string | TaggedTemplateValue<string>): ChoiceItemBuilder<AnyAsset> {
41
+ return this.set("id", value);
42
+ }
43
+
44
+ /** The id used for replay tests. */
45
+ withAutomationId(value: string | TaggedTemplateValue<string>): ChoiceItemBuilder<AnyAsset> {
46
+ return this.set("automationId", value);
47
+ }
48
+
49
+ /** The label describing the choice. */
50
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
51
+ const extractedValue = { asset: value };
52
+
53
+ return this.set("label", extractedValue);
54
+ }
55
+
56
+ /** The icon describing the choice. */
57
+ withIcon(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
58
+ const extractedValue = { asset: value };
59
+
60
+ return this.set("icon", extractedValue);
61
+ }
62
+
63
+ /** The help for the choice. */
64
+ withHelp(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
65
+ const extractedValue = { asset: value };
66
+
67
+ return this.set("help", extractedValue);
68
+ }
69
+
70
+ /** Support the legacy choiceHelp prop. No storybook docs for this; deprecated in favour of the "help" field. */
71
+ withChoiceHelp(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
72
+ const extractedValue = { asset: value };
73
+
74
+ return this.set("choiceHelp", extractedValue);
75
+ }
76
+
77
+ /** The description of the choice. */
78
+ withDescription(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
79
+ const extractedValue = { asset: value };
80
+
81
+ return this.set("description", extractedValue);
82
+ }
83
+
84
+ /** The footer of the choice. */
85
+ withFooter(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
86
+ const extractedValue = { asset: value };
87
+
88
+ return this.set("footer", extractedValue);
89
+ }
90
+
91
+ /** The value to set when this choice is selected */
92
+ withValue(value: string | number | false | true): ChoiceItemBuilder<AnyAsset> {
93
+ return this.set("value", value);
94
+ }
95
+
96
+ /** The details shown when a user selects the choice item */
97
+ withChoiceDetail(value: Asset | FluentBuilder<Asset, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
98
+ const extractedValue = { asset: value };
99
+
100
+ return this.set("choiceDetail", extractedValue);
101
+ }
102
+
103
+ /** Any modifiers for the current item. No storybook docs for this as "readonly" (the only modifier) shouldn't be used anymore. */
104
+ withModifiers(value: Array<ChoiceInputModifier | FluentBuilder<ChoiceInputModifier, BaseBuildContext>>): ChoiceItemBuilder<AnyAsset> {
105
+ return this.set("modifiers", value);
106
+ }
107
+
108
+ /** MetaData for the choiceItem */
109
+ withMetaData(value: ChoiceItemMetadata | FluentBuilder<ChoiceItemMetadata, BaseBuildContext>): ChoiceItemBuilder<AnyAsset> {
110
+ return this.set("metaData", value);
111
+ }
112
+
113
+ /**
114
+ * Builds the final ChoiceItem object
115
+ * @param context - Optional build context for nested builders
116
+ */
117
+ build(context?: BaseBuildContext): ChoiceItem<AnyAsset> {
118
+ return this.buildWithDefaults(ChoiceItemBuilder.defaults, context);
119
+ }
120
+
121
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
122
+ return createInspectMethod("ChoiceItemBuilder", this.values);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Creates a new ChoiceItem builder
128
+ * @param initial Optional initial values
129
+ * @returns A fluent builder for ChoiceItem
130
+ */
131
+ export function choiceItem<AnyAsset extends Asset<string> = Asset<string>>(initial?: Partial<ChoiceItem<AnyAsset>>): ChoiceItemBuilder<AnyAsset> {
132
+ return new ChoiceItemBuilder<AnyAsset>(initial);
133
+ }
@@ -0,0 +1,117 @@
1
+ import type { Collection, CollectionMetaData, CalloutModifier, TagModifier } from "../types/collection.js";
2
+ import type { ActionAsset, ActionMetaData } from "../types/action.js";
3
+ import type { Asset, AssetWrapper } from "@player-ui/types";
4
+ import { type FluentBuilder, type BaseBuildContext, FluentBuilderBase, createInspectMethod } from "../../../gen/common.js";
5
+ import type { TaggedTemplateValue } from "@player-tools/fluent";
6
+
7
+ export interface CollectionBuilderMethods<AnyAsset extends Asset<string> = Asset<string>> {
8
+ /** The collection items to show */
9
+ withValues(value: Array<Asset | FluentBuilder<Asset, BaseBuildContext>>): CollectionBuilder<AnyAsset>;
10
+ /** The additional information to show */
11
+ withAdditionalInfo(value: Asset | FluentBuilder<Asset, BaseBuildContext>): CollectionBuilder<AnyAsset>;
12
+ /** The result text to show */
13
+ withResultText(value: AssetWrapper | Array<AssetWrapper>): CollectionBuilder<AnyAsset>;
14
+ /** The label defining the collection */
15
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): CollectionBuilder<AnyAsset>;
16
+ /** Actions attached to the collection */
17
+ withActions(value: Array<Asset | FluentBuilder<Asset, BaseBuildContext>>): CollectionBuilder<AnyAsset>;
18
+ /** Extra data associated with the collection */
19
+ withMetaData(value: CollectionMetaData | FluentBuilder<CollectionMetaData, BaseBuildContext>): CollectionBuilder<AnyAsset>;
20
+ /** Ways to modify how the component looks */
21
+ withModifiers(value: Array<CalloutModifier | TagModifier>): CollectionBuilder<AnyAsset>;
22
+ /** Each asset requires a unique id per view */
23
+ withId(value: string | TaggedTemplateValue<string>): CollectionBuilder<AnyAsset>;
24
+ /** The asset type determines the semantics of how a user interacts with a page */
25
+ withType(value: "collection"): CollectionBuilder<AnyAsset>;
26
+ }
27
+
28
+ /**
29
+ * A builder for Collection
30
+ */
31
+ export class CollectionBuilder<AnyAsset extends Asset<string> = Asset<string>> extends FluentBuilderBase<Collection<AnyAsset>> implements CollectionBuilderMethods<AnyAsset>, FluentBuilder<Collection<AnyAsset>, BaseBuildContext> {
32
+ private static readonly defaults: Record<string, unknown> = { id: "", type: "collection" };
33
+ private static readonly __arrayProperties__: ReadonlySet<string> = new Set(["actions", "values"]);
34
+
35
+ /** The collection items to show */
36
+ withValues(value: Array<Asset | FluentBuilder<Asset, BaseBuildContext>>): CollectionBuilder<AnyAsset> {
37
+ const extractedValue = { asset: value };
38
+
39
+ return this.set("values", extractedValue);
40
+ }
41
+
42
+ /** The additional information to show */
43
+ withAdditionalInfo(value: Asset | FluentBuilder<Asset, BaseBuildContext>): CollectionBuilder<AnyAsset> {
44
+ const extractedValue = { asset: value };
45
+
46
+ return this.set("additionalInfo", extractedValue);
47
+ }
48
+
49
+ /** The result text to show */
50
+ withResultText(value: AssetWrapper | Array<AssetWrapper>): CollectionBuilder<AnyAsset> {
51
+ return this.set("resultText", value);
52
+ }
53
+
54
+ /** The label defining the collection */
55
+ withLabel(value: Asset | FluentBuilder<Asset, BaseBuildContext>): CollectionBuilder<AnyAsset> {
56
+ const extractedValue = { asset: value };
57
+
58
+ return this.set("label", extractedValue);
59
+ }
60
+
61
+ /** Actions attached to the collection */
62
+ withActions(value: Array<Asset | FluentBuilder<Asset, BaseBuildContext>>): CollectionBuilder<AnyAsset> {
63
+ const extractedValue = { asset: value };
64
+
65
+ return this.set("actions", extractedValue);
66
+ }
67
+
68
+ /** Extra data associated with the collection */
69
+ withMetaData(value: CollectionMetaData | FluentBuilder<CollectionMetaData, BaseBuildContext>): CollectionBuilder<AnyAsset> {
70
+ return this.set("metaData", value);
71
+ }
72
+
73
+ /** Ways to modify how the component looks */
74
+ withModifiers(value: Array<CalloutModifier | TagModifier>): CollectionBuilder<AnyAsset> {
75
+ return this.set("modifiers", value);
76
+ }
77
+
78
+ /** Each asset requires a unique id per view */
79
+ withId(value: string | TaggedTemplateValue<string>): CollectionBuilder<AnyAsset> {
80
+ return this.set("id", value);
81
+ }
82
+
83
+ /** The asset type determines the semantics of how a user interacts with a page */
84
+ withType(value: "collection"): CollectionBuilder<AnyAsset> {
85
+ return this.set("type", value);
86
+ }
87
+
88
+ /**
89
+ * Set additional properties with dynamic keys
90
+ * @param props - Object with dynamic properties
91
+ */
92
+ withAdditionalProperties(props: Record<string, unknown>): CollectionBuilder<AnyAsset> {
93
+ Object.assign(this.values, props);
94
+ return this as CollectionBuilder<AnyAsset>;
95
+ }
96
+
97
+ /**
98
+ * Builds the final Collection object
99
+ * @param context - Optional build context for nested builders
100
+ */
101
+ build(context?: BaseBuildContext): Collection<AnyAsset> {
102
+ return this.buildWithDefaults(CollectionBuilder.defaults, context);
103
+ }
104
+
105
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
106
+ return createInspectMethod("CollectionBuilder", this.values);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Creates a new Collection builder
112
+ * @param initial Optional initial values
113
+ * @returns A fluent builder for Collection
114
+ */
115
+ export function collection<AnyAsset extends Asset<string> = Asset<string>>(initial?: Partial<Collection<AnyAsset>>): CollectionBuilder<AnyAsset> {
116
+ return new CollectionBuilder<AnyAsset>(initial);
117
+ }
@@ -0,0 +1,7 @@
1
+ export * from './action.builder.js';
2
+ export * from './collection.builder.js';
3
+ export * from './text.builder.js';
4
+ export * from './info.builder.js';
5
+ export * from './input.builder.js';
6
+ export * from './choice.builder.js';
7
+ export * from './choiceItem.builder.js';
@@ -0,0 +1,80 @@
1
+ import type { InfoAsset } from "../types/info.js";
2
+ import type { Asset, AssetWrapper } from "@player-ui/types";
3
+ import { type FluentBuilder, type BaseBuildContext, FluentBuilderBase, createInspectMethod } from "../../../gen/common.js";
4
+ import type { TaggedTemplateValue } from "@player-tools/fluent";
5
+
6
+ export interface InfoAssetBuilderMethods {
7
+ withPrimaryInfo(value: Array<Asset | FluentBuilder<Asset, BaseBuildContext>>): InfoAssetBuilder;
8
+ withTitle(value: Asset | FluentBuilder<Asset, BaseBuildContext>): InfoAssetBuilder;
9
+ withSubtitle(value: Asset | FluentBuilder<Asset, BaseBuildContext>): InfoAssetBuilder;
10
+ /** Each asset requires a unique id per view */
11
+ withId(value: string | TaggedTemplateValue<string>): InfoAssetBuilder;
12
+ /** The asset type determines the semantics of how a user interacts with a page */
13
+ withType(value: "info"): InfoAssetBuilder;
14
+ }
15
+
16
+ /**
17
+ * A builder for InfoAsset
18
+ */
19
+ export class InfoAssetBuilder extends FluentBuilderBase<InfoAsset> implements InfoAssetBuilderMethods, FluentBuilder<InfoAsset, BaseBuildContext> {
20
+ private static readonly defaults: Record<string, unknown> = { primaryInfo: [], id: "", type: "info" };
21
+ private static readonly __arrayProperties__: ReadonlySet<string> = new Set(["primaryInfo"]);
22
+
23
+ withPrimaryInfo(value: Array<Asset | FluentBuilder<Asset, BaseBuildContext>>): InfoAssetBuilder {
24
+ const extractedValue = { asset: value };
25
+
26
+ return this.set("primaryInfo", extractedValue);
27
+ }
28
+
29
+ withTitle(value: Asset | FluentBuilder<Asset, BaseBuildContext>): InfoAssetBuilder {
30
+ const extractedValue = { asset: value };
31
+
32
+ return this.set("title", extractedValue);
33
+ }
34
+
35
+ withSubtitle(value: Asset | FluentBuilder<Asset, BaseBuildContext>): InfoAssetBuilder {
36
+ const extractedValue = { asset: value };
37
+
38
+ return this.set("subtitle", extractedValue);
39
+ }
40
+
41
+ /** Each asset requires a unique id per view */
42
+ withId(value: string | TaggedTemplateValue<string>): InfoAssetBuilder {
43
+ return this.set("id", value);
44
+ }
45
+
46
+ /** The asset type determines the semantics of how a user interacts with a page */
47
+ withType(value: "info"): InfoAssetBuilder {
48
+ return this.set("type", value);
49
+ }
50
+
51
+ /**
52
+ * Set additional properties with dynamic keys
53
+ * @param props - Object with dynamic properties
54
+ */
55
+ withAdditionalProperties(props: Record<string, unknown>): InfoAssetBuilder {
56
+ Object.assign(this.values, props);
57
+ return this as InfoAssetBuilder;
58
+ }
59
+
60
+ /**
61
+ * Builds the final InfoAsset object
62
+ * @param context - Optional build context for nested builders
63
+ */
64
+ build(context?: BaseBuildContext): InfoAsset {
65
+ return this.buildWithDefaults(InfoAssetBuilder.defaults, context);
66
+ }
67
+
68
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
69
+ return createInspectMethod("InfoAssetBuilder", this.values);
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Creates a new InfoAsset builder
75
+ * @param initial Optional initial values
76
+ * @returns A fluent builder for InfoAsset
77
+ */
78
+ export function info(initial?: Partial<InfoAsset>): InfoAssetBuilder {
79
+ return new InfoAssetBuilder(initial);
80
+ }