@dreamboard-games/sdk 0.2.1-alpha.1 → 0.3.0-alpha.1

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 (372) hide show
  1. package/dist/{HandView-ncJIVLhN.d.ts → HandView-PYDmehVD.d.ts} +1 -1
  2. package/dist/{ResourceCounter-CTREyF73.d.ts → ResourceCounter-BTXklCEZ.d.ts} +1 -1
  3. package/dist/{ThemeProvider-BBMVT3KG.d.ts → ThemeProvider-DvMl17Ny.d.ts} +1 -1
  4. package/dist/{chunk-NKCRKGR2.js → chunk-3RQEICD3.js} +2 -2
  5. package/dist/{chunk-ZABVH7AO.js → chunk-ADYH6PVT.js} +1336 -1363
  6. package/dist/chunk-ADYH6PVT.js.map +1 -0
  7. package/dist/{chunk-PEI3FIL2.js → chunk-P7VMTJ5D.js} +2 -2
  8. package/dist/{chunk-PEI3FIL2.js.map → chunk-P7VMTJ5D.js.map} +1 -1
  9. package/dist/{chunk-WG4JQL3S.js → chunk-QZ6X4B5P.js} +1177 -1109
  10. package/dist/chunk-QZ6X4B5P.js.map +1 -0
  11. package/dist/{chunk-MZNVHMJ5.js → chunk-TXXLS3OI.js} +405 -309
  12. package/dist/chunk-TXXLS3OI.js.map +1 -0
  13. package/dist/{chunk-FDNZTDD6.js → chunk-W6SGFWXH.js} +48 -44
  14. package/dist/chunk-W6SGFWXH.js.map +1 -0
  15. package/dist/{chunk-MKXPVOUT.js → chunk-Y2AFYBMB.js} +48 -4
  16. package/dist/chunk-Y2AFYBMB.js.map +1 -0
  17. package/dist/{index-BwqPQtBu.d.ts → codegen.d.ts} +57 -565
  18. package/dist/{infrastructure/workspace-codegen.js → codegen.js} +3 -3
  19. package/dist/{components-BoiVSYqx.d.ts → components-DaIqi9QM.d.ts} +48 -37
  20. package/dist/{hex-board-view-1iAyJRFn.d.ts → hex-board-view-UCUjMALd.d.ts} +2 -2
  21. package/dist/{infrastructure/reducer-bundle-abi.d.ts → index.d-BGqVifr_.d.ts} +289 -10
  22. package/dist/index.js +1 -1
  23. package/dist/package-set.d.ts +2 -2
  24. package/dist/package-set.js +1 -1
  25. package/dist/primitive-props-BNHDkgd7.d.ts +16 -0
  26. package/dist/reducer-contract.d.ts +3 -0
  27. package/dist/{infrastructure/reducer-bundle-abi.js → reducer-contract.js} +4 -4
  28. package/dist/reducer.d.ts +185 -179
  29. package/dist/reducer.js +1363 -1372
  30. package/dist/reducer.js.map +1 -1
  31. package/dist/runtime/primitives.d.ts +9 -9
  32. package/dist/runtime/primitives.js +7 -7
  33. package/dist/runtime/runtime-api.d.ts +2 -0
  34. package/dist/runtime/runtime-api.js +1 -0
  35. package/dist/runtime/workspace-contract.d.ts +62 -17
  36. package/dist/runtime/workspace-contract.js +5 -6
  37. package/dist/{runtime-api-CPLm_XDG.d.ts → runtime-api-tGL3ArsB.d.ts} +103 -4
  38. package/dist/runtime.d.ts +11 -57
  39. package/dist/runtime.js +487 -8
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/testing.d.ts +4 -4
  42. package/dist/testing.js.map +1 -1
  43. package/dist/types.d.ts +1531 -85
  44. package/dist/types.js +1 -3
  45. package/dist/types.js.map +1 -1
  46. package/dist/ui/components.d.ts +7 -8
  47. package/dist/ui/components.js +1 -1
  48. package/dist/ui/defaults.d.ts +1 -1
  49. package/dist/ui/{types/player-state.d.ts → player-state.d.ts} +2 -2
  50. package/dist/{ui-contract-rzKBwOLC.d.ts → ui-contract-SctM4ibF.d.ts} +155 -150
  51. package/dist/ui.d.ts +10 -11
  52. package/dist/ui.js +2 -2
  53. package/package.json +30 -75
  54. package/dist/bundle-CDd5FKeD.d.ts +0 -283
  55. package/dist/cards-Sl3b40Mv.d.ts +0 -13
  56. package/dist/chunk-326PGVAA.js +0 -34
  57. package/dist/chunk-326PGVAA.js.map +0 -1
  58. package/dist/chunk-FDNZTDD6.js.map +0 -1
  59. package/dist/chunk-I46YJSOD.js +0 -1
  60. package/dist/chunk-MKXPVOUT.js.map +0 -1
  61. package/dist/chunk-MZNVHMJ5.js.map +0 -1
  62. package/dist/chunk-T52J5RMF.js +0 -1
  63. package/dist/chunk-WG4JQL3S.js.map +0 -1
  64. package/dist/chunk-XV6D3ET4.js +0 -485
  65. package/dist/chunk-XV6D3ET4.js.map +0 -1
  66. package/dist/chunk-ZABVH7AO.js.map +0 -1
  67. package/dist/generated/runtime/primitives.d.ts +0 -13
  68. package/dist/generated/runtime/primitives.js +0 -181
  69. package/dist/generated/runtime/primitives.js.map +0 -1
  70. package/dist/generated/runtime-api.d.ts +0 -3
  71. package/dist/generated/runtime-api.js +0 -2
  72. package/dist/generated/runtime.d.ts +0 -15
  73. package/dist/generated/runtime.js +0 -19
  74. package/dist/generated/runtime.js.map +0 -1
  75. package/dist/generated/workspace-contract.d.ts +0 -15
  76. package/dist/generated/workspace-contract.js +0 -15
  77. package/dist/generated/workspace-contract.js.map +0 -1
  78. package/dist/infrastructure/reducer-bundle-abi.js.map +0 -1
  79. package/dist/infrastructure/workspace-codegen.d.ts +0 -53
  80. package/dist/infrastructure/workspace-codegen.js.map +0 -1
  81. package/dist/manifest-contract-BNHVGFtU.d.ts +0 -9
  82. package/dist/primitive-props-DpKs-GCr.d.ts +0 -11
  83. package/dist/runtime/types/runtime-api.d.ts +0 -1
  84. package/dist/runtime/types/runtime-api.js +0 -2
  85. package/dist/runtime/types/runtime-api.js.map +0 -1
  86. package/dist/runtime-api-3dshj6kK.d.ts +0 -101
  87. package/dist/slots-1GPGihk8.d.ts +0 -8
  88. package/src/browser-interaction/attributes.ts +0 -211
  89. package/src/browser-interaction/canonical.ts +0 -77
  90. package/src/browser-interaction/constants.ts +0 -77
  91. package/src/browser-interaction/effects.ts +0 -176
  92. package/src/browser-interaction/index.ts +0 -111
  93. package/src/browser-interaction/normalize.ts +0 -997
  94. package/src/browser-interaction/registry.ts +0 -70
  95. package/src/browser-interaction/resolve.ts +0 -596
  96. package/src/browser-interaction/schemas.ts +0 -152
  97. package/src/browser-interaction/types.ts +0 -304
  98. package/src/browser-interaction.ts +0 -1
  99. package/src/generated/reducer-contract/builders.ts +0 -90
  100. package/src/generated/reducer-contract/version.ts +0 -9
  101. package/src/generated/reducer-contract/wire.ts +0 -100
  102. package/src/generated/reducer-contract/zod.ts +0 -103
  103. package/src/generated/runtime/primitives.ts +0 -2
  104. package/src/generated/runtime-api.ts +0 -5
  105. package/src/generated/runtime.ts +0 -35
  106. package/src/generated/workspace-contract.ts +0 -2
  107. package/src/index.ts +0 -7
  108. package/src/infrastructure/reducer-bundle-abi.ts +0 -8
  109. package/src/infrastructure/reducer-contract/bundle.ts +0 -37
  110. package/src/infrastructure/workspace-codegen/hex-geometry.ts +0 -69
  111. package/src/infrastructure/workspace-codegen/index.ts +0 -64
  112. package/src/infrastructure/workspace-codegen/manifest-contract.ts +0 -6632
  113. package/src/infrastructure/workspace-codegen/manifest-validation.ts +0 -795
  114. package/src/infrastructure/workspace-codegen/ownership.ts +0 -131
  115. package/src/infrastructure/workspace-codegen/preset-card-sets.ts +0 -169
  116. package/src/infrastructure/workspace-codegen/seeds.ts +0 -1705
  117. package/src/infrastructure/workspace-codegen.ts +0 -1
  118. package/src/package-set.ts +0 -19
  119. package/src/reducer/authoring/contract.ts +0 -157
  120. package/src/reducer/authoring/effect.ts +0 -224
  121. package/src/reducer/authoring/game.ts +0 -23
  122. package/src/reducer/authoring/interaction.ts +0 -98
  123. package/src/reducer/authoring/phase.ts +0 -300
  124. package/src/reducer/authoring/types.ts +0 -70
  125. package/src/reducer/authoring/validation.ts +0 -382
  126. package/src/reducer/authoring/view-stage.ts +0 -68
  127. package/src/reducer/authoring.ts +0 -29
  128. package/src/reducer/bundle/ingress-bundle.ts +0 -491
  129. package/src/reducer/bundle/trusted/engine-instruction-resolver.ts +0 -254
  130. package/src/reducer/bundle/trusted/flow-instruction-resolver.ts +0 -73
  131. package/src/reducer/bundle/trusted/instruction-runner.ts +0 -414
  132. package/src/reducer/bundle/trusted/interaction-authorization.ts +0 -137
  133. package/src/reducer/bundle/trusted/interaction-collectors.ts +0 -859
  134. package/src/reducer/bundle/trusted/interaction-decision.ts +0 -747
  135. package/src/reducer/bundle/trusted/interaction-resolver.ts +0 -95
  136. package/src/reducer/bundle/trusted/interaction-types.ts +0 -174
  137. package/src/reducer/bundle/trusted/lifecycle-runner.ts +0 -427
  138. package/src/reducer/bundle/trusted/projection-builder.ts +0 -680
  139. package/src/reducer/bundle/trusted/projection-context.ts +0 -39
  140. package/src/reducer/bundle/trusted/rng-sampler.ts +0 -150
  141. package/src/reducer/bundle/trusted/runtime-registry.ts +0 -120
  142. package/src/reducer/bundle/trusted/runtime-scope.ts +0 -336
  143. package/src/reducer/bundle/trusted/simultaneous-player.ts +0 -97
  144. package/src/reducer/bundle/trusted/stage-resolver.ts +0 -87
  145. package/src/reducer/bundle/trusted/static-projection.ts +0 -116
  146. package/src/reducer/bundle/trusted/trusted-runtime-args.ts +0 -97
  147. package/src/reducer/bundle/trusted/trusted-runtime-result.ts +0 -39
  148. package/src/reducer/bundle/trusted/trusted-setup-profiles.ts +0 -43
  149. package/src/reducer/bundle/trusted/trusted-state-codec.ts +0 -48
  150. package/src/reducer/bundle/trusted-bundle.ts +0 -97
  151. package/src/reducer/bundle/types.ts +0 -171
  152. package/src/reducer/bundle.ts +0 -2
  153. package/src/reducer/client-param-schemas.ts +0 -57
  154. package/src/reducer/compose.ts +0 -34
  155. package/src/reducer/core/runtime-input.ts +0 -30
  156. package/src/reducer/core/runtime-instruction.ts +0 -59
  157. package/src/reducer/core/types.ts +0 -62
  158. package/src/reducer/definition-index.ts +0 -277
  159. package/src/reducer/derived.ts +0 -106
  160. package/src/reducer/effects.ts +0 -92
  161. package/src/reducer/engine/runtime-instruction-engine.ts +0 -155
  162. package/src/reducer/ingress/decode-runtime-input.ts +0 -7
  163. package/src/reducer/ingress/decode-session-state.ts +0 -9
  164. package/src/reducer/ingress/encode-session-state.ts +0 -6
  165. package/src/reducer/ingress/input-codec.ts +0 -18
  166. package/src/reducer/ingress/phase-schemas.ts +0 -62
  167. package/src/reducer/ingress/raw-types.ts +0 -107
  168. package/src/reducer/ingress/runtime-codec.ts +0 -14
  169. package/src/reducer/ingress/runtime-payload.ts +0 -13
  170. package/src/reducer/ingress/session-codec.ts +0 -392
  171. package/src/reducer/ingress/types.ts +0 -6
  172. package/src/reducer/inputs/boardInput.ts +0 -217
  173. package/src/reducer/inputs/boardTarget.ts +0 -190
  174. package/src/reducer/inputs/cardInput.ts +0 -86
  175. package/src/reducer/inputs/cardTarget.ts +0 -101
  176. package/src/reducer/inputs/choiceTarget.ts +0 -104
  177. package/src/reducer/inputs/defineInputs.ts +0 -71
  178. package/src/reducer/inputs/formInput.ts +0 -809
  179. package/src/reducer/inputs/many.ts +0 -120
  180. package/src/reducer/inputs/promptInput.ts +0 -87
  181. package/src/reducer/inputs/rngInput.ts +0 -58
  182. package/src/reducer/inputs/targetRule.ts +0 -123
  183. package/src/reducer/inputs.ts +0 -41
  184. package/src/reducer/model/definition.ts +0 -1072
  185. package/src/reducer/model/extract.ts +0 -745
  186. package/src/reducer/model/manifest.ts +0 -570
  187. package/src/reducer/model/queries.ts +0 -641
  188. package/src/reducer/model/runtime.ts +0 -264
  189. package/src/reducer/model/spec.ts +0 -1386
  190. package/src/reducer/model/table.ts +0 -260
  191. package/src/reducer/model.ts +0 -7
  192. package/src/reducer/ops.ts +0 -1034
  193. package/src/reducer/parse-utils.ts +0 -28
  194. package/src/reducer/per-player.ts +0 -422
  195. package/src/reducer/rng.ts +0 -69
  196. package/src/reducer/schema-helpers.ts +0 -185
  197. package/src/reducer/setup-bootstrap-helpers.ts +0 -171
  198. package/src/reducer/setup-bootstrap.ts +0 -481
  199. package/src/reducer/table-ops.ts +0 -2671
  200. package/src/reducer/table-queries.ts +0 -372
  201. package/src/reducer/transaction.ts +0 -120
  202. package/src/reducer.ts +0 -314
  203. package/src/runtime/primitives.ts +0 -1
  204. package/src/runtime/types/runtime-api.ts +0 -1
  205. package/src/runtime/workspace-contract.ts +0 -32
  206. package/src/runtime-internal/components/InteractionForm.tsx +0 -1647
  207. package/src/runtime-internal/components/PluginRuntime.tsx +0 -105
  208. package/src/runtime-internal/components/board/target-layer.ts +0 -72
  209. package/src/runtime-internal/context/ClientParamSchemaContext.tsx +0 -44
  210. package/src/runtime-internal/context/InteractionDraftContext.tsx +0 -279
  211. package/src/runtime-internal/context/PluginSessionContext.tsx +0 -47
  212. package/src/runtime-internal/context/PluginStateContext.tsx +0 -303
  213. package/src/runtime-internal/context/RuntimeContext.tsx +0 -96
  214. package/src/runtime-internal/defaults/components.tsx +0 -409
  215. package/src/runtime-internal/defaults/index.ts +0 -11
  216. package/src/runtime-internal/errors/ValidationError.ts +0 -29
  217. package/src/runtime-internal/hooks/useActivePlayers.ts +0 -33
  218. package/src/runtime-internal/hooks/useBoardInteractions.ts +0 -727
  219. package/src/runtime-internal/hooks/useGameSelector.ts +0 -105
  220. package/src/runtime-internal/hooks/useGameView.ts +0 -9
  221. package/src/runtime-internal/hooks/useInteractionByKey.ts +0 -354
  222. package/src/runtime-internal/hooks/useInteractionHandle.ts +0 -438
  223. package/src/runtime-internal/hooks/useIsMyTurn.ts +0 -20
  224. package/src/runtime-internal/hooks/useLobby.ts +0 -76
  225. package/src/runtime-internal/hooks/useMe.ts +0 -48
  226. package/src/runtime-internal/hooks/usePlayerInfo.ts +0 -28
  227. package/src/runtime-internal/hooks/usePlayerTurnOrder.ts +0 -23
  228. package/src/runtime-internal/hooks/usePluginRuntime.ts +0 -147
  229. package/src/runtime-internal/hooks/useSeatInbox.ts +0 -61
  230. package/src/runtime-internal/hooks/useSimultaneousPhase.ts +0 -10
  231. package/src/runtime-internal/index.ts +0 -42
  232. package/src/runtime-internal/internal.ts +0 -43
  233. package/src/runtime-internal/plugin-styles.css +0 -250
  234. package/src/runtime-internal/primitives/board.tsx +0 -530
  235. package/src/runtime-internal/primitives/dialog-lifecycle.ts +0 -58
  236. package/src/runtime-internal/primitives/dice.tsx +0 -79
  237. package/src/runtime-internal/primitives/game-ui-provider.tsx +0 -35
  238. package/src/runtime-internal/primitives/game.tsx +0 -387
  239. package/src/runtime-internal/primitives/hand-intent-adapter.ts +0 -147
  240. package/src/runtime-internal/primitives/hand-surface.tsx +0 -594
  241. package/src/runtime-internal/primitives/index.ts +0 -196
  242. package/src/runtime-internal/primitives/interaction-form-binding.tsx +0 -56
  243. package/src/runtime-internal/primitives/interaction-submit.ts +0 -90
  244. package/src/runtime-internal/primitives/interaction.tsx +0 -1146
  245. package/src/runtime-internal/primitives/phase.tsx +0 -43
  246. package/src/runtime-internal/primitives/player-roster.tsx +0 -302
  247. package/src/runtime-internal/primitives/primitive-props.tsx +0 -101
  248. package/src/runtime-internal/primitives/prompt.tsx +0 -255
  249. package/src/runtime-internal/primitives/ui.tsx +0 -60
  250. package/src/runtime-internal/primitives/zone.tsx +0 -791
  251. package/src/runtime-internal/reducer.ts +0 -30
  252. package/src/runtime-internal/runtime/createPluginRuntimeAPI.ts +0 -605
  253. package/src/runtime-internal/types/plugin-state.ts +0 -514
  254. package/src/runtime-internal/types/reducer-state.ts +0 -24
  255. package/src/runtime-internal/types/runtime-api.ts +0 -114
  256. package/src/runtime-internal/ui-contract.ts +0 -519
  257. package/src/runtime-internal/utils/browser-interaction-effects.ts +0 -240
  258. package/src/runtime-internal/utils/card-intent-adapter.ts +0 -546
  259. package/src/runtime-internal/utils/interaction-draft-digest.ts +0 -252
  260. package/src/runtime-internal/utils/interaction-inputs.ts +0 -492
  261. package/src/runtime-internal/utils/interaction-labels.ts +0 -23
  262. package/src/runtime-internal/utils/interaction-router.ts +0 -273
  263. package/src/runtime-internal/utils/interaction-status.ts +0 -74
  264. package/src/runtime-internal/utils/semantic-projection-digest.ts +0 -407
  265. package/src/runtime-internal/workspace-contract.ts +0 -1170
  266. package/src/runtime.ts +0 -34
  267. package/src/testing/create-expect-api.ts +0 -352
  268. package/src/testing/create-test-runtime.ts +0 -381
  269. package/src/testing/definitions.ts +0 -127
  270. package/src/testing/index.ts +0 -3
  271. package/src/testing.ts +0 -1
  272. package/src/type-stubs/manifest-contract.d.ts +0 -42
  273. package/src/type-stubs/manifest-contract.js +0 -72
  274. package/src/type-stubs/ui-contract.d.ts +0 -5
  275. package/src/type-stubs/ui-contract.js +0 -1
  276. package/src/types/authoring-card-properties.type-test.ts +0 -266
  277. package/src/types/authoring.ts +0 -1282
  278. package/src/types/cards.ts +0 -19
  279. package/src/types/contracts.ts +0 -1550
  280. package/src/types/generated-helpers.ts +0 -35
  281. package/src/types/index.ts +0 -147
  282. package/src/types/slots.ts +0 -11
  283. package/src/types.ts +0 -1
  284. package/src/ui/components/ActionButton.tsx +0 -97
  285. package/src/ui/components/ActionPanel.tsx +0 -315
  286. package/src/ui/components/Card.tsx +0 -378
  287. package/src/ui/components/CardDragSurface.tsx +0 -1076
  288. package/src/ui/components/ChromeSuppressionContext.tsx +0 -70
  289. package/src/ui/components/CostDisplay.tsx +0 -145
  290. package/src/ui/components/DiceRoller.tsx +0 -581
  291. package/src/ui/components/Drawer.tsx +0 -180
  292. package/src/ui/components/ErrorBoundary.tsx +0 -275
  293. package/src/ui/components/GameEndDisplay.tsx +0 -398
  294. package/src/ui/components/GameSkeleton.tsx +0 -260
  295. package/src/ui/components/Hand.tsx +0 -468
  296. package/src/ui/components/HandDock.tsx +0 -299
  297. package/src/ui/components/HandView.tsx +0 -441
  298. package/src/ui/components/MobileHandTray.tsx +0 -381
  299. package/src/ui/components/MoreActions.tsx +0 -143
  300. package/src/ui/components/PhaseIndicator.tsx +0 -341
  301. package/src/ui/components/PlayArea.tsx +0 -146
  302. package/src/ui/components/PrimaryActionButton.tsx +0 -336
  303. package/src/ui/components/PrimaryButton.tsx +0 -45
  304. package/src/ui/components/ResourceCounter.tsx +0 -270
  305. package/src/ui/components/StagingZone.tsx +0 -134
  306. package/src/ui/components/ThemedButton.tsx +0 -113
  307. package/src/ui/components/Toast.tsx +0 -264
  308. package/src/ui/components/board/HexGrid.tsx +0 -1297
  309. package/src/ui/components/board/NetworkGraph.tsx +0 -476
  310. package/src/ui/components/board/SlotSystem.tsx +0 -388
  311. package/src/ui/components/board/SquareGrid.tsx +0 -1165
  312. package/src/ui/components/board/TrackBoard.tsx +0 -496
  313. package/src/ui/components/board/ZoneMap.tsx +0 -448
  314. package/src/ui/components/board/hex-board-view.ts +0 -123
  315. package/src/ui/components/board/index.ts +0 -142
  316. package/src/ui/components/board/interaction-accessibility.ts +0 -21
  317. package/src/ui/components/board/target-layer.ts +0 -67
  318. package/src/ui/components/card-render-content.type-test.ts +0 -27
  319. package/src/ui/components/hand-layout-math.ts +0 -163
  320. package/src/ui/components/hand-pointer-engine.ts +0 -413
  321. package/src/ui/components/index.ts +0 -245
  322. package/src/ui/components.ts +0 -1
  323. package/src/ui/defaults/components.tsx +0 -106
  324. package/src/ui/defaults/index.ts +0 -8
  325. package/src/ui/defaults.ts +0 -1
  326. package/src/ui/errors/ValidationError.ts +0 -29
  327. package/src/ui/helpers/cards.ts +0 -19
  328. package/src/ui/helpers/track-board.ts +0 -211
  329. package/src/ui/hooks/useBoardTopology.ts +0 -316
  330. package/src/ui/hooks/useCards.ts +0 -10
  331. package/src/ui/hooks/useHandCardPointer.ts +0 -381
  332. package/src/ui/hooks/useHandLayout.ts +0 -378
  333. package/src/ui/hooks/useHandPresentation.ts +0 -121
  334. package/src/ui/hooks/useHexBoard.ts +0 -74
  335. package/src/ui/hooks/useHexGrid.ts +0 -185
  336. package/src/ui/hooks/useIsMobile.ts +0 -35
  337. package/src/ui/hooks/usePanZoom.ts +0 -278
  338. package/src/ui/hooks/useSquareBoard.ts +0 -124
  339. package/src/ui/hooks/useSquareGrid.ts +0 -328
  340. package/src/ui/index.ts +0 -98
  341. package/src/ui/internal/ui/alert.tsx +0 -51
  342. package/src/ui/internal/ui/button.tsx +0 -58
  343. package/src/ui/internal/ui/dialog.tsx +0 -134
  344. package/src/ui/internal/ui/input.tsx +0 -21
  345. package/src/ui/internal/ui/label.tsx +0 -21
  346. package/src/ui/internal/ui/select.tsx +0 -129
  347. package/src/ui/internal/ui/tooltip.tsx +0 -54
  348. package/src/ui/internal/ui/utils.ts +0 -5
  349. package/src/ui/plugin-styles.css +0 -250
  350. package/src/ui/primitives/dialog-lifecycle.ts +0 -58
  351. package/src/ui/primitives/dice.tsx +0 -79
  352. package/src/ui/primitives/primitive-props.tsx +0 -101
  353. package/src/ui/theme/ThemeProvider.tsx +0 -252
  354. package/src/ui/theme/board.ts +0 -61
  355. package/src/ui/theme/css-vars.ts +0 -105
  356. package/src/ui/theme/derive.ts +0 -240
  357. package/src/ui/theme/index.ts +0 -61
  358. package/src/ui/theme/presets/arcade.ts +0 -261
  359. package/src/ui/theme/presets/studio.ts +0 -261
  360. package/src/ui/theme/presets/tabletop.ts +0 -266
  361. package/src/ui/theme/tokens.ts +0 -392
  362. package/src/ui/types/hex-color.ts +0 -20
  363. package/src/ui/types/player-state.ts +0 -463
  364. package/src/ui/types/tiled-board.ts +0 -785
  365. package/src/ui/types/visual-state.ts +0 -137
  366. package/src/ui.ts +0 -1
  367. /package/dist/{chunk-NKCRKGR2.js.map → chunk-3RQEICD3.js.map} +0 -0
  368. /package/dist/{chunk-I46YJSOD.js.map → codegen.js.map} +0 -0
  369. /package/dist/{chunk-T52J5RMF.js.map → reducer-contract.js.map} +0 -0
  370. /package/dist/{generated → runtime}/runtime-api.js.map +0 -0
  371. /package/dist/ui/{types/player-state.js → player-state.js} +0 -0
  372. /package/dist/ui/{types/player-state.js.map → player-state.js.map} +0 -0
@@ -1,1647 +0,0 @@
1
- import {
2
- useEffect,
3
- useId,
4
- useMemo,
5
- useState,
6
- type ButtonHTMLAttributes,
7
- type CSSProperties,
8
- type FormEvent,
9
- type ReactNode,
10
- } from "react";
11
- import * as AccordionPrimitive from "@radix-ui/react-accordion";
12
- import {
13
- Input,
14
- Label,
15
- Select,
16
- SelectContent,
17
- SelectItem,
18
- SelectTrigger,
19
- surfaceStyle,
20
- useTheme,
21
- useThemeCssVars,
22
- } from "../../ui.js";
23
- import {
24
- createGameplayActuatorAttributes,
25
- createGameplayInteractionRootAttributes,
26
- type GameplayActuatorAttributesInput,
27
- type BrowserInteractionAttributeMap,
28
- type BrowserInteractionCandidateState,
29
- type GameplayBrowserInteractionIntent,
30
- } from "../../browser-interaction/index.js";
31
- import type {
32
- DraftValidation,
33
- InteractionHandle,
34
- InteractionParamsShape,
35
- } from "../hooks/useInteractionHandle.js";
36
- import type {
37
- InteractionChoiceOption,
38
- InteractionDescriptor,
39
- InteractionInputDescriptor,
40
- InputDomain,
41
- } from "../types/plugin-state.js";
42
- import { interactionLabel } from "../utils/interaction-labels.js";
43
- import {
44
- inputTargetKind,
45
- isResolvedTargetDomain,
46
- isTargetDomain,
47
- resolveInputDomain,
48
- resolveInteractionInputs,
49
- toggleManyValue,
50
- } from "../utils/interaction-inputs.js";
51
- import { interactionDraftDigestForValues } from "../utils/interaction-draft-digest.js";
52
- import { isInteractionAvailable } from "../utils/interaction-status.js";
53
- import {
54
- gameplayCandidateMetadata,
55
- gameplayPreparationPatternsForDescriptor,
56
- gameplayResourceMetadata,
57
- gameplayScalarFillMetadata,
58
- gameplayScalarStepMetadata,
59
- gameplaySubmitMetadata,
60
- } from "../utils/browser-interaction-effects.js";
61
- import { useChromeSuppression, ThemedButton } from "../../ui.js";
62
-
63
- export interface InteractionFieldRenderProps<
64
- Params extends InteractionParamsShape = InteractionParamsShape,
65
- Key extends keyof Params & string = keyof Params & string,
66
- > {
67
- descriptor: InteractionDescriptor;
68
- input: InteractionInputDescriptor & { key: Key };
69
- handle: InteractionHandle<Params>;
70
- value: Params[Key] | undefined;
71
- setValue: (value: Params[Key]) => void;
72
- clearValue: () => void;
73
- errors: readonly string[];
74
- missing: boolean;
75
- disabled: boolean;
76
- }
77
-
78
- export type InteractionFieldRenderMap<
79
- Params extends InteractionParamsShape = InteractionParamsShape,
80
- > = Partial<{
81
- [K in keyof Params & string]: (
82
- props: InteractionFieldRenderProps<Params, K>,
83
- ) => ReactNode;
84
- }>;
85
-
86
- export interface InteractionSlotComponentProps {
87
- children?: ReactNode;
88
- }
89
-
90
- export type InteractionButtonSlotProps = InteractionSlotComponentProps &
91
- Omit<
92
- ButtonHTMLAttributes<HTMLButtonElement>,
93
- "children" | "disabled" | "type" | "value"
94
- >;
95
-
96
- export interface InteractionTargetSlotProps extends Omit<
97
- ButtonHTMLAttributes<HTMLButtonElement>,
98
- | "children"
99
- | "disabled"
100
- | "aria-disabled"
101
- | "aria-pressed"
102
- | "onClick"
103
- | "type"
104
- | "value"
105
- > {
106
- value: string;
107
- children?: ReactNode;
108
- }
109
-
110
- export interface InteractionOptionsSlotProps {
111
- children: (option: { value: string | null; label: string }) => ReactNode;
112
- }
113
-
114
- export interface InteractionCardsSlotProps {
115
- children: (card: { id: string }) => ReactNode;
116
- }
117
-
118
- export interface InteractionValueSlotProps {
119
- children: (value: unknown) => ReactNode;
120
- }
121
-
122
- export interface InteractionInputSlot {
123
- Field: (props: InteractionSlotComponentProps) => ReactNode;
124
- Default: (props: InteractionSlotComponentProps) => ReactNode;
125
- Target: (props: InteractionTargetSlotProps) => ReactNode;
126
- Card: (props: InteractionTargetSlotProps) => ReactNode;
127
- Cards: (props: InteractionCardsSlotProps) => ReactNode;
128
- Options: (props: InteractionOptionsSlotProps) => ReactNode;
129
- Value: (props: InteractionValueSlotProps) => ReactNode;
130
- Label: (props: InteractionSlotComponentProps) => ReactNode;
131
- Message: (props: InteractionSlotComponentProps) => ReactNode;
132
- }
133
-
134
- export type InteractionInputRenderMap = Record<
135
- string,
136
- (slot: InteractionInputSlot) => ReactNode
137
- >;
138
-
139
- export interface InteractionSubmitSlot {
140
- Button: (props: InteractionButtonSlotProps) => ReactNode;
141
- }
142
-
143
- export interface InteractionFieldProps<
144
- Params extends InteractionParamsShape = InteractionParamsShape,
145
- Key extends keyof Params & string = keyof Params & string,
146
- > {
147
- descriptor: InteractionDescriptor;
148
- inputKey: Key;
149
- handle: InteractionHandle<Params>;
150
- errors?: readonly string[];
151
- missing?: boolean;
152
- disabled?: boolean;
153
- render?: InteractionFieldRenderMap<Params>[Key];
154
- }
155
-
156
- export interface InteractionFormProps<
157
- Params extends InteractionParamsShape = InteractionParamsShape,
158
- DefaultedKeys extends keyof Params & string = never,
159
- > {
160
- descriptor: InteractionDescriptor;
161
- handle: InteractionHandle<Params, DefaultedKeys>;
162
- fields?: ReadonlyArray<keyof Params & string>;
163
- hiddenFields?: ReadonlyArray<keyof Params & string>;
164
- renderFields?: InteractionFieldRenderMap<Params>;
165
- inputs?: InteractionInputRenderMap;
166
- submit?: (
167
- slot: InteractionSubmitSlot,
168
- descriptor: InteractionDescriptor,
169
- ) => ReactNode;
170
- title?: ReactNode;
171
- description?: ReactNode;
172
- submitLabel?: ReactNode;
173
- cancelLabel?: ReactNode;
174
- onCancel?: () => void;
175
- onSubmitSuccess?: () => void;
176
- disabled?: boolean;
177
- accordion?: boolean;
178
- defaultOpen?: boolean;
179
- style?: CSSProperties;
180
- }
181
-
182
- const EMPTY_FIELD_ERRORS: readonly string[] = [];
183
- const GAMEPLAY_BROWSER_SCOPE_ID = "runtime";
184
-
185
- function gameplayInteractionRootAttributes({
186
- descriptor,
187
- draftValues,
188
- ready,
189
- available,
190
- }: {
191
- descriptor: InteractionDescriptor;
192
- draftValues?: Readonly<Record<string, unknown>>;
193
- ready: boolean;
194
- available: boolean;
195
- }): BrowserInteractionAttributeMap {
196
- return createGameplayInteractionRootAttributes({
197
- scopeId: GAMEPLAY_BROWSER_SCOPE_ID,
198
- interactionKey: descriptor.interactionKey,
199
- interactionId: descriptor.interactionId,
200
- ...(descriptor.descriptorDigest !== undefined
201
- ? { descriptorDigest: descriptor.descriptorDigest }
202
- : {}),
203
- ...(descriptor.draftDigest !== undefined
204
- ? {
205
- draftDigest: interactionDraftDigestForValues(
206
- descriptor,
207
- draftValues ?? {},
208
- ),
209
- }
210
- : {}),
211
- readiness: available ? (ready ? "ready" : "blocked") : "unavailable",
212
- });
213
- }
214
-
215
- function gameplayActuatorAttributes({
216
- descriptor,
217
- inputKey,
218
- intent,
219
- candidateValue,
220
- candidateState,
221
- semanticEffects,
222
- acceptedEffectPatterns,
223
- preparationPatterns,
224
- draftValues,
225
- enabled,
226
- actuatorKind,
227
- actuatorId,
228
- }: {
229
- descriptor: InteractionDescriptor;
230
- inputKey?: string;
231
- intent: GameplayBrowserInteractionIntent;
232
- candidateValue?: unknown;
233
- candidateState?: BrowserInteractionCandidateState;
234
- semanticEffects?: GameplayActuatorAttributesInput["semanticEffects"];
235
- acceptedEffectPatterns?: GameplayActuatorAttributesInput["acceptedEffectPatterns"];
236
- preparationPatterns?: GameplayActuatorAttributesInput["preparationPatterns"];
237
- draftValues?: Readonly<Record<string, unknown>>;
238
- enabled: boolean;
239
- actuatorKind: GameplayActuatorAttributesInput["actuatorKind"];
240
- actuatorId: string;
241
- }): BrowserInteractionAttributeMap {
242
- return createGameplayActuatorAttributes({
243
- scopeId: GAMEPLAY_BROWSER_SCOPE_ID,
244
- interactionKey: descriptor.interactionKey,
245
- interactionId: descriptor.interactionId,
246
- intent,
247
- enabled,
248
- actuatorKind,
249
- actuatorId,
250
- ...(descriptor.descriptorDigest !== undefined
251
- ? { descriptorDigest: descriptor.descriptorDigest }
252
- : {}),
253
- ...(descriptor.draftDigest !== undefined
254
- ? {
255
- draftDigest: interactionDraftDigestForValues(
256
- descriptor,
257
- draftValues ?? {},
258
- ),
259
- }
260
- : {}),
261
- ...(inputKey !== undefined ? { inputKey } : {}),
262
- ...(candidateValue !== undefined ? { candidateValue } : {}),
263
- ...(candidateState !== undefined ? { candidateState } : {}),
264
- ...(semanticEffects !== undefined ? { semanticEffects } : {}),
265
- ...(acceptedEffectPatterns !== undefined ? { acceptedEffectPatterns } : {}),
266
- ...(preparationPatterns !== undefined ? { preparationPatterns } : {}),
267
- });
268
- }
269
-
270
- export function InteractionForm<
271
- Params extends InteractionParamsShape = InteractionParamsShape,
272
- DefaultedKeys extends keyof Params & string = never,
273
- >({
274
- descriptor,
275
- handle,
276
- fields,
277
- hiddenFields,
278
- renderFields,
279
- inputs,
280
- submit: renderSubmit,
281
- title,
282
- description,
283
- submitLabel,
284
- cancelLabel = "Cancel",
285
- onCancel,
286
- onSubmitSuccess,
287
- disabled = false,
288
- accordion = true,
289
- defaultOpen = false,
290
- style,
291
- }: InteractionFormProps<Params, DefaultedKeys>) {
292
- const theme = useTheme();
293
- const fallbackLabel = interactionLabel(descriptor);
294
- const formId = useId();
295
- useChromeSuppression(formId, true);
296
- const [pending, setPending] = useState(false);
297
- const [validation, setValidation] = useState<DraftValidation<Params> | null>(
298
- null,
299
- );
300
- const [formError, setFormError] = useState<string | null>(null);
301
- const [accordionOpen, setAccordionOpen] = useState(defaultOpen);
302
- const hidden = useMemo(() => new Set(hiddenFields ?? []), [hiddenFields]);
303
- const visibleInputs = useMemo(() => {
304
- if (inputs) {
305
- const rendered = new Set(Object.keys(inputs));
306
- return resolveInteractionInputs(
307
- descriptor,
308
- handle.values as Readonly<Record<string, unknown>>,
309
- ).filter((input) => rendered.has(input.key));
310
- }
311
- const allowed = fields ? new Set(fields) : null;
312
- return defaultFormInputs(
313
- descriptor,
314
- handle.values as Readonly<Record<string, unknown>>,
315
- ).filter((input) => {
316
- const key = input.key as keyof Params & string;
317
- if (allowed && !allowed.has(key)) return false;
318
- return !hidden.has(key);
319
- });
320
- }, [descriptor, fields, hidden, handle.values, inputs]);
321
-
322
- const currentValidation = validation;
323
- const fieldErrors = (currentValidation?.fieldErrors ?? {}) as Partial<
324
- Record<keyof Params & string, readonly string[]>
325
- >;
326
- const missing = new Set<string>(currentValidation?.missing ?? []);
327
- const formErrors = [
328
- ...(currentValidation?.formErrors ?? []),
329
- ...(formError ? [formError] : []),
330
- ];
331
- const isDisabled = disabled || pending || !isInteractionAvailable(descriptor);
332
- const useAccordion = accordion && visibleInputs.length > 0;
333
- const rootBrowserAttributes = gameplayInteractionRootAttributes({
334
- descriptor,
335
- draftValues: handle.values as Readonly<Record<string, unknown>>,
336
- ready: handle.isReady,
337
- available: !isDisabled,
338
- });
339
- const armBrowserAttributes = gameplayActuatorAttributes({
340
- descriptor,
341
- draftValues: handle.values as Readonly<Record<string, unknown>>,
342
- intent: "arm",
343
- enabled: !isDisabled,
344
- actuatorKind: "click",
345
- actuatorId: "arm",
346
- preparationPatterns: gameplayPreparationPatternsForDescriptor(
347
- descriptor,
348
- handle.values as Readonly<Record<string, unknown>>,
349
- ),
350
- });
351
- const submitMetadata = gameplaySubmitMetadata({ descriptor });
352
- const submitBrowserAttributes = gameplayActuatorAttributes({
353
- descriptor,
354
- draftValues: handle.values as Readonly<Record<string, unknown>>,
355
- intent: submitMetadata.intent,
356
- enabled: !isDisabled && handle.isReady,
357
- actuatorKind: "click",
358
- actuatorId: "submit",
359
- semanticEffects: submitMetadata.semanticEffects,
360
- });
361
-
362
- useEffect(() => {
363
- setAccordionOpen(defaultOpen);
364
- }, [defaultOpen, descriptor.interactionId]);
365
-
366
- const containerStyle: CSSProperties = {
367
- ...surfaceStyle(theme, { tone: "card" }),
368
- display: "flex",
369
- flexDirection: "column",
370
- gap: theme.space[2],
371
- padding: theme.space[3],
372
- minWidth: "min(100%, 280px)",
373
- boxSizing: "border-box",
374
- fontFamily: theme.typography.fontFamily.body,
375
- ...style,
376
- };
377
-
378
- const submit = async (event: FormEvent) => {
379
- event.preventDefault();
380
- if (isDisabled) return;
381
- const nextValidation = handle.validateDraft();
382
- setValidation(nextValidation);
383
- setFormError(null);
384
- if (!nextValidation.ok) {
385
- setAccordionOpen(true);
386
- return;
387
- }
388
- setPending(true);
389
- try {
390
- await handle.submitDraft();
391
- onSubmitSuccess?.();
392
- setAccordionOpen(defaultOpen);
393
- } catch (error) {
394
- setAccordionOpen(true);
395
- setFormError(
396
- error instanceof Error
397
- ? error.message
398
- : "Interaction submission failed",
399
- );
400
- } finally {
401
- setPending(false);
402
- }
403
- };
404
-
405
- const header = (
406
- <div style={{ display: "flex", flexDirection: "column", gap: 2 }}>
407
- <strong
408
- style={{
409
- fontFamily: theme.typography.fontFamily.display,
410
- fontSize: theme.typography.fontSize.md,
411
- color: theme.semantic.text.primary,
412
- }}
413
- >
414
- {title ?? fallbackLabel}
415
- </strong>
416
- {description ? (
417
- <span
418
- style={{
419
- fontSize: theme.typography.fontSize.sm,
420
- color: theme.semantic.text.muted,
421
- }}
422
- >
423
- {description}
424
- </span>
425
- ) : null}
426
- </div>
427
- );
428
-
429
- const fieldsContent =
430
- visibleInputs.length > 0 ? (
431
- <div
432
- style={{
433
- display: "flex",
434
- flexDirection: "column",
435
- gap: theme.space[3],
436
- }}
437
- >
438
- {visibleInputs.map((input) => {
439
- const key = input.key as keyof Params & string;
440
- const inputRenderer = inputs?.[key];
441
- return (
442
- <InteractionField<Params>
443
- key={input.key}
444
- descriptor={descriptor}
445
- inputKey={key}
446
- handle={handle}
447
- errors={fieldErrors[key] ?? []}
448
- missing={missing.has(key)}
449
- disabled={isDisabled}
450
- render={
451
- inputRenderer
452
- ? ({ input, errors, missing, disabled }) =>
453
- inputRenderer(
454
- createInteractionInputSlot({
455
- descriptor,
456
- input,
457
- handle,
458
- errors,
459
- missing,
460
- disabled,
461
- }),
462
- )
463
- : renderFields?.[key]
464
- }
465
- />
466
- );
467
- })}
468
- </div>
469
- ) : null;
470
-
471
- if (visibleInputs.length === 0 && !handle.isReady) {
472
- throw new Error(
473
- `InteractionForm '${descriptor.interactionKey}' has required inputs that cannot be rendered by the default form. Provide renderFields, select on a surface, or use a default-renderable input domain.`,
474
- );
475
- }
476
-
477
- const formErrorContent =
478
- formErrors.length > 0 ? (
479
- <div
480
- role="alert"
481
- style={{
482
- display: "flex",
483
- flexDirection: "column",
484
- gap: theme.space[1],
485
- color: theme.semantic.intent.danger.solid,
486
- fontSize: theme.typography.fontSize.sm,
487
- }}
488
- >
489
- {formErrors.map((error) => (
490
- <span key={error}>{error}</span>
491
- ))}
492
- </div>
493
- ) : null;
494
-
495
- const actions = (
496
- <div
497
- style={{
498
- display: "flex",
499
- gap: theme.space[2],
500
- justifyContent: "flex-end",
501
- }}
502
- >
503
- {onCancel ? (
504
- <ThemedButton
505
- type="button"
506
- variant="secondary"
507
- size="sm"
508
- disabled={pending}
509
- onClick={onCancel}
510
- className="h-9 px-3 text-sm"
511
- >
512
- {cancelLabel}
513
- </ThemedButton>
514
- ) : null}
515
- {renderSubmit ? (
516
- renderSubmit(
517
- {
518
- Button: ({ children, ...buttonProps }) => (
519
- <ThemedButton
520
- type="submit"
521
- variant="primary"
522
- size="sm"
523
- disabled={isDisabled}
524
- className="h-9 px-3 text-sm"
525
- {...submitBrowserAttributes}
526
- {...buttonProps}
527
- >
528
- {pending
529
- ? "Submitting..."
530
- : (children ?? submitLabel ?? fallbackLabel)}
531
- </ThemedButton>
532
- ),
533
- },
534
- descriptor,
535
- )
536
- ) : (
537
- <ThemedButton
538
- type="submit"
539
- variant="primary"
540
- size="sm"
541
- disabled={isDisabled}
542
- className="h-9 px-3 text-sm"
543
- {...submitBrowserAttributes}
544
- >
545
- {pending ? "Submitting..." : (submitLabel ?? fallbackLabel)}
546
- </ThemedButton>
547
- )}
548
- </div>
549
- );
550
-
551
- const body = (
552
- <>
553
- {fieldsContent}
554
- {formErrorContent}
555
- {actions}
556
- </>
557
- );
558
-
559
- return (
560
- <form
561
- data-interaction-form
562
- data-interaction-id={descriptor.interactionId}
563
- onSubmit={(event) => void submit(event)}
564
- style={containerStyle}
565
- {...rootBrowserAttributes}
566
- >
567
- {useAccordion ? (
568
- <AccordionPrimitive.Root
569
- type="single"
570
- collapsible
571
- value={accordionOpen ? "fields" : undefined}
572
- onValueChange={(value: string) =>
573
- setAccordionOpen(value === "fields")
574
- }
575
- >
576
- <AccordionPrimitive.Item value="fields">
577
- <AccordionPrimitive.Header style={{ margin: 0 }}>
578
- <AccordionPrimitive.Trigger
579
- {...armBrowserAttributes}
580
- style={{
581
- alignItems: "center",
582
- appearance: "none",
583
- background: "transparent",
584
- border: 0,
585
- color: theme.semantic.text.primary,
586
- cursor: "pointer",
587
- display: "flex",
588
- fontFamily: theme.typography.fontFamily.display,
589
- fontSize: theme.typography.fontSize.md,
590
- fontWeight: theme.typography.fontWeight.bold,
591
- justifyContent: "space-between",
592
- padding: 0,
593
- textAlign: "left",
594
- width: "100%",
595
- }}
596
- >
597
- <span>{title ?? fallbackLabel}</span>
598
- <span aria-hidden>{accordionOpen ? "−" : "+"}</span>
599
- </AccordionPrimitive.Trigger>
600
- </AccordionPrimitive.Header>
601
- <AccordionPrimitive.Content>
602
- <div
603
- style={{
604
- display: "flex",
605
- flexDirection: "column",
606
- gap: theme.space[2],
607
- marginTop: theme.space[2],
608
- }}
609
- >
610
- {description ? (
611
- <span
612
- style={{
613
- fontSize: theme.typography.fontSize.sm,
614
- color: theme.semantic.text.muted,
615
- }}
616
- >
617
- {description}
618
- </span>
619
- ) : null}
620
- {body}
621
- </div>
622
- </AccordionPrimitive.Content>
623
- </AccordionPrimitive.Item>
624
- </AccordionPrimitive.Root>
625
- ) : (
626
- <>
627
- {header}
628
- {body}
629
- </>
630
- )}
631
- </form>
632
- );
633
- }
634
-
635
- function createInteractionInputSlot<
636
- Params extends InteractionParamsShape,
637
- Key extends keyof Params & string,
638
- >({
639
- descriptor,
640
- input,
641
- handle,
642
- errors,
643
- missing,
644
- disabled,
645
- }: {
646
- descriptor: InteractionDescriptor;
647
- input: InteractionInputDescriptor & { key: Key };
648
- handle: InteractionHandle<Params>;
649
- errors: readonly string[];
650
- missing: boolean;
651
- disabled: boolean;
652
- }): InteractionInputSlot {
653
- const value = handle.values[input.key] as Params[Key] | undefined;
654
- const resolvedInput = resolveInputDomain(
655
- input,
656
- handle.values as Readonly<Record<string, unknown>>,
657
- ) as InteractionInputDescriptor & { key: Key };
658
-
659
- const targetButton = ({
660
- value: targetValue,
661
- children,
662
- kind,
663
- ...buttonProps
664
- }: InteractionTargetSlotProps & { kind: "card" | "target" }) => {
665
- const domain = resolvedInput.domain;
666
- const eligible =
667
- isResolvedTargetDomain(domain) &&
668
- domain.eligibleTargets.includes(targetValue);
669
- const selection = isTargetDomain(domain) ? domain.selection : undefined;
670
- const currentValue = handle.values[input.key];
671
- const selected =
672
- selection?.mode === "many"
673
- ? Array.isArray(currentValue) &&
674
- currentValue.map(String).includes(targetValue)
675
- : currentValue !== undefined && String(currentValue) === targetValue;
676
- const isDisabled = disabled || !eligible;
677
- const dataAttribute =
678
- kind === "card"
679
- ? { "data-dreamboard-interaction-card-slot": "" }
680
- : { "data-dreamboard-interaction-target-slot": "" };
681
- const browserAttributes = gameplayActuatorAttributes({
682
- descriptor,
683
- draftValues: handle.values as Readonly<Record<string, unknown>>,
684
- inputKey: input.key,
685
- intent: selection?.mode === "many" ? "toggle" : "select",
686
- candidateValue: targetValue,
687
- candidateState: selected ? "selected" : "unselected",
688
- enabled: !isDisabled,
689
- actuatorKind: "click",
690
- actuatorId: `${kind}:${input.key}:${targetValue}`,
691
- semanticEffects: gameplayCandidateMetadata({
692
- descriptor,
693
- draftValues: handle.values as Readonly<Record<string, unknown>>,
694
- inputKey: input.key,
695
- candidateValue: targetValue,
696
- intent: selection?.mode === "many" ? "toggle" : "select",
697
- }).semanticEffects,
698
- });
699
- return (
700
- <button
701
- type="button"
702
- disabled={isDisabled}
703
- aria-disabled={isDisabled}
704
- aria-pressed={selected}
705
- data-input-name={input.key}
706
- data-target-kind={inputTargetKind(domain)}
707
- data-target-value={targetValue}
708
- data-eligible={eligible}
709
- data-selected={selected || undefined}
710
- data-disabled={isDisabled || undefined}
711
- {...dataAttribute}
712
- {...browserAttributes}
713
- {...buttonProps}
714
- onClick={() => {
715
- if (isDisabled) return;
716
- const nextValue =
717
- selection?.mode === "many"
718
- ? toggleManyValue(currentValue, targetValue, selection)
719
- : targetValue;
720
- handle.setInput(input.key, nextValue as Params[Key]);
721
- }}
722
- >
723
- {children ?? targetValue}
724
- </button>
725
- );
726
- };
727
-
728
- return {
729
- Field: () => (
730
- <DefaultInteractionField
731
- descriptor={descriptor}
732
- input={resolvedInput}
733
- handle={handle}
734
- value={value}
735
- setValue={(next) => handle.setInput(input.key, next)}
736
- clearValue={() => handle.clearInput(input.key)}
737
- errors={errors}
738
- missing={missing}
739
- disabled={disabled}
740
- />
741
- ),
742
- Default: ({ children }) => {
743
- const hasDefault = "defaultValue" in input;
744
- const isDisabled = disabled || !hasDefault;
745
- const browserAttributes = gameplayActuatorAttributes({
746
- descriptor,
747
- draftValues: handle.values as Readonly<Record<string, unknown>>,
748
- inputKey: input.key,
749
- intent: "select",
750
- candidateValue: input.defaultValue,
751
- candidateState: "unselected",
752
- enabled: !isDisabled,
753
- actuatorKind: "click",
754
- actuatorId: `default:${input.key}`,
755
- semanticEffects: hasDefault
756
- ? gameplayCandidateMetadata({
757
- descriptor,
758
- draftValues: handle.values as Readonly<Record<string, unknown>>,
759
- inputKey: input.key,
760
- candidateValue: input.defaultValue,
761
- intent: "select",
762
- }).semanticEffects
763
- : undefined,
764
- });
765
- return (
766
- <button
767
- type="button"
768
- disabled={isDisabled}
769
- aria-disabled={isDisabled}
770
- data-dreamboard-interaction-default-slot=""
771
- data-input-name={input.key}
772
- data-disabled={isDisabled || undefined}
773
- {...browserAttributes}
774
- onClick={() => {
775
- if (isDisabled) return;
776
- handle.setInput(input.key, input.defaultValue as Params[Key]);
777
- }}
778
- >
779
- {children ?? "Use default"}
780
- </button>
781
- );
782
- },
783
- Target: (props) => targetButton({ ...props, kind: "target" }),
784
- Card: (props) => targetButton({ ...props, kind: "card" }),
785
- Cards: ({ children }) => {
786
- const domain = resolvedInput.domain;
787
- const targets = isResolvedTargetDomain(domain)
788
- ? domain.eligibleTargets
789
- : [];
790
- return <>{targets.map((id) => children({ id }))}</>;
791
- },
792
- Options: ({ children }) => {
793
- const domain = resolvedInput.domain;
794
- const choices =
795
- domain.type === "choice" || domain.type === "choiceList"
796
- ? (domain.choices ?? [])
797
- : [];
798
- return <>{choices.map((choice) => children(choice))}</>;
799
- },
800
- Value: ({ children }) => <>{children(value)}</>,
801
- Label: ({ children }) => <>{children ?? labelForInput(resolvedInput)}</>,
802
- Message: ({ children }) => {
803
- const message = children ?? errors[0] ?? (missing ? "Required" : null);
804
- return message ? (
805
- <span role="alert" data-dreamboard-interaction-message-slot="">
806
- {message}
807
- </span>
808
- ) : null;
809
- },
810
- };
811
- }
812
-
813
- export function InteractionField<
814
- Params extends InteractionParamsShape = InteractionParamsShape,
815
- Key extends keyof Params & string = keyof Params & string,
816
- >({
817
- descriptor,
818
- inputKey,
819
- handle,
820
- errors = EMPTY_FIELD_ERRORS,
821
- missing = false,
822
- disabled = false,
823
- render,
824
- }: InteractionFieldProps<Params, Key>) {
825
- const input = descriptor.inputs.find(
826
- (candidate) => candidate.key === inputKey,
827
- );
828
- if (!input) return null;
829
- const typedInput = resolveInputDomain(
830
- input,
831
- handle.values as Readonly<Record<string, unknown>>,
832
- ) as InteractionInputDescriptor & { key: Key };
833
- const value = handle.values[inputKey] as Params[Key] | undefined;
834
- const props: InteractionFieldRenderProps<Params, Key> = {
835
- descriptor,
836
- input: typedInput,
837
- handle,
838
- value,
839
- setValue: (next) => handle.setInput(inputKey, next),
840
- clearValue: () => handle.clearInput(inputKey),
841
- errors,
842
- missing,
843
- disabled,
844
- };
845
- if (render) return <>{render(props)}</>;
846
- return <DefaultInteractionField {...props} />;
847
- }
848
-
849
- export function hasDefaultInteractionFormFields(
850
- descriptor: Pick<InteractionDescriptor, "inputs">,
851
- ): boolean {
852
- return defaultFormInputs(descriptor).length > 0;
853
- }
854
-
855
- export function defaultFormInputs(
856
- descriptor: Pick<InteractionDescriptor, "inputs">,
857
- values: Readonly<Record<string, unknown>> = {},
858
- ): InteractionInputDescriptor[] {
859
- return resolveInteractionInputs(descriptor, values).filter((input) => {
860
- switch (input.domain.type) {
861
- case "choice":
862
- case "choiceList":
863
- case "resourceMap":
864
- case "boundedNumber":
865
- return true;
866
- case "cardTarget":
867
- case "boardTarget":
868
- return input.domain.selection?.mode === "many";
869
- }
870
- });
871
- }
872
-
873
- function DefaultInteractionField<
874
- Params extends InteractionParamsShape,
875
- Key extends keyof Params & string,
876
- >(props: InteractionFieldRenderProps<Params, Key>) {
877
- const { input } = props;
878
- switch (input.domain.type) {
879
- case "choice":
880
- if (input.domain.selection?.mode === "many") {
881
- return (
882
- <ChoiceListField
883
- {...props}
884
- domain={{
885
- type: "choiceList",
886
- choices: input.domain.choices,
887
- min: input.domain.selection.min ?? 0,
888
- max: input.domain.selection.max,
889
- selection: input.domain.selection,
890
- }}
891
- />
892
- );
893
- }
894
- return <ChoiceField {...props} domain={input.domain} />;
895
- case "choiceList":
896
- return <ChoiceListField {...props} domain={input.domain} />;
897
- case "resourceMap":
898
- return <ResourceMapField {...props} domain={input.domain} />;
899
- case "boundedNumber":
900
- return <BoundedNumberField {...props} domain={input.domain} />;
901
- case "cardTarget":
902
- case "boardTarget":
903
- return <TargetSummaryField {...props} domain={input.domain} />;
904
- }
905
- }
906
-
907
- function FieldFrame({
908
- label,
909
- controlId,
910
- errors,
911
- missing,
912
- children,
913
- }: {
914
- label: ReactNode;
915
- controlId?: string;
916
- errors: readonly string[];
917
- missing: boolean;
918
- children: ReactNode;
919
- }) {
920
- const theme = useTheme();
921
- const messages = errors.length > 0 ? errors : missing ? ["Required"] : [];
922
- return (
923
- <div
924
- style={{
925
- display: "flex",
926
- flexDirection: "column",
927
- gap: theme.space[1],
928
- fontSize: theme.typography.fontSize.sm,
929
- color: theme.semantic.text.primary,
930
- }}
931
- >
932
- <Label
933
- htmlFor={controlId}
934
- style={{
935
- color: theme.semantic.text.primary,
936
- fontWeight: theme.typography.fontWeight.bold,
937
- }}
938
- >
939
- {label}
940
- </Label>
941
- {children}
942
- {messages.length > 0 ? (
943
- <span
944
- role="alert"
945
- style={{
946
- display: "flex",
947
- flexDirection: "column",
948
- gap: 2,
949
- color: theme.semantic.intent.danger.solid,
950
- fontSize: theme.typography.fontSize.xs,
951
- }}
952
- >
953
- {messages.map((message) => (
954
- <span key={message}>{message}</span>
955
- ))}
956
- </span>
957
- ) : null}
958
- </div>
959
- );
960
- }
961
-
962
- function ChoiceOptionLabel({ choice }: { choice: InteractionChoiceOption }) {
963
- const theme = useTheme();
964
- return (
965
- <span
966
- style={{
967
- display: "inline-flex",
968
- alignItems: "center",
969
- gap: 6,
970
- minWidth: 0,
971
- }}
972
- >
973
- <span
974
- style={{
975
- display: "inline-flex",
976
- alignItems: "center",
977
- gap: 6,
978
- minWidth: 0,
979
- }}
980
- >
981
- {choice.icon ? (
982
- <span aria-hidden style={{ fontSize: "1.1em", lineHeight: 1 }}>
983
- {choice.icon}
984
- </span>
985
- ) : null}
986
- <span style={{ overflow: "hidden", textOverflow: "ellipsis" }}>
987
- {choice.label}
988
- </span>
989
- </span>
990
- {choice.badge ? (
991
- <span
992
- style={{
993
- borderRadius: 999,
994
- background: theme.semantic.surface.inset,
995
- color: theme.semantic.text.muted,
996
- fontSize: theme.typography.fontSize.xs,
997
- fontWeight: theme.typography.fontWeight.bold,
998
- lineHeight: 1,
999
- padding: "3px 6px",
1000
- whiteSpace: "nowrap",
1001
- }}
1002
- >
1003
- {choice.badge}
1004
- </span>
1005
- ) : null}
1006
- </span>
1007
- );
1008
- }
1009
-
1010
- function ChoiceDescription({ choice }: { choice?: InteractionChoiceOption }) {
1011
- const theme = useTheme();
1012
- const message = choice?.disabledReason ?? choice?.description;
1013
- if (!message) return null;
1014
- return (
1015
- <span
1016
- style={{
1017
- color: choice?.disabledReason
1018
- ? theme.semantic.intent.danger.solid
1019
- : theme.semantic.text.muted,
1020
- fontSize: theme.typography.fontSize.xs,
1021
- }}
1022
- >
1023
- {message}
1024
- </span>
1025
- );
1026
- }
1027
-
1028
- const NULL_CHOICE_SELECT_VALUE = "__dreamboard_null_choice__";
1029
-
1030
- function choiceRenderKey(choice: InteractionChoiceOption): string {
1031
- return choice.value === null ? NULL_CHOICE_SELECT_VALUE : choice.value;
1032
- }
1033
-
1034
- function encodeChoiceSelectValue(value: unknown): string | undefined {
1035
- if (value === null) return NULL_CHOICE_SELECT_VALUE;
1036
- return typeof value === "string" ? value : undefined;
1037
- }
1038
-
1039
- function decodeChoiceSelectValue(value: string): string | null {
1040
- return value === NULL_CHOICE_SELECT_VALUE ? null : value;
1041
- }
1042
-
1043
- function ChoiceField<
1044
- Params extends InteractionParamsShape,
1045
- Key extends keyof Params & string,
1046
- >({
1047
- descriptor,
1048
- handle,
1049
- input,
1050
- value,
1051
- setValue,
1052
- errors,
1053
- missing,
1054
- disabled,
1055
- domain,
1056
- }: InteractionFieldRenderProps<Params, Key> & {
1057
- domain: Extract<InputDomain, { type: "choice" }>;
1058
- }) {
1059
- const theme = useTheme();
1060
- const themeCssVars = useThemeCssVars();
1061
- const choices = domain.choices ?? [];
1062
- const controlId = useId();
1063
- const selectedChoice =
1064
- typeof value === "string" || value === null
1065
- ? choices.find((choice) => choice.value === value)
1066
- : undefined;
1067
- if (choices.length > 0 && choices.length <= 3) {
1068
- return (
1069
- <FieldFrame
1070
- label={labelForInput(input)}
1071
- errors={errors}
1072
- missing={missing}
1073
- >
1074
- <span
1075
- style={{
1076
- display: "inline-flex",
1077
- flexWrap: "wrap",
1078
- gap: theme.space[1],
1079
- }}
1080
- >
1081
- {choices.map((choice) => {
1082
- const selected = value === choice.value;
1083
- const isDisabled = disabled || choice.disabled;
1084
- return (
1085
- <ThemedButton
1086
- key={choiceRenderKey(choice)}
1087
- type="button"
1088
- variant={selected ? "primary" : "secondary"}
1089
- size="sm"
1090
- disabled={isDisabled}
1091
- aria-pressed={selected}
1092
- title={choice.disabledReason ?? choice.description}
1093
- {...gameplayActuatorAttributes({
1094
- descriptor,
1095
- draftValues: handle.values as Readonly<
1096
- Record<string, unknown>
1097
- >,
1098
- inputKey: input.key,
1099
- intent: "select",
1100
- candidateValue: choice.value,
1101
- candidateState: selected ? "selected" : "unselected",
1102
- enabled: !isDisabled,
1103
- actuatorKind: "click",
1104
- actuatorId: `choice:${input.key}:${choiceRenderKey(choice)}`,
1105
- semanticEffects: gameplayCandidateMetadata({
1106
- descriptor,
1107
- draftValues: handle.values as Readonly<
1108
- Record<string, unknown>
1109
- >,
1110
- inputKey: input.key,
1111
- candidateValue: choice.value,
1112
- intent: "select",
1113
- }).semanticEffects,
1114
- })}
1115
- onClick={() => setValue(choice.value as Params[Key])}
1116
- className="h-8 px-3 text-sm"
1117
- >
1118
- <ChoiceOptionLabel choice={choice} />
1119
- </ThemedButton>
1120
- );
1121
- })}
1122
- </span>
1123
- </FieldFrame>
1124
- );
1125
- }
1126
- return (
1127
- <FieldFrame
1128
- label={labelForInput(input)}
1129
- controlId={controlId}
1130
- errors={errors}
1131
- missing={missing}
1132
- >
1133
- <Select
1134
- disabled={disabled}
1135
- value={encodeChoiceSelectValue(value)}
1136
- onValueChange={(next: string) =>
1137
- setValue(decodeChoiceSelectValue(next) as Params[Key])
1138
- }
1139
- >
1140
- <SelectTrigger
1141
- id={controlId}
1142
- size="sm"
1143
- className="w-full bg-white"
1144
- {...gameplayActuatorAttributes({
1145
- descriptor,
1146
- draftValues: handle.values as Readonly<Record<string, unknown>>,
1147
- inputKey: input.key,
1148
- intent: "reveal",
1149
- enabled: !disabled,
1150
- actuatorKind: "click",
1151
- actuatorId: `choice-reveal:${input.key}`,
1152
- preparationPatterns: gameplayPreparationPatternsForDescriptor(
1153
- { inputs: [input] },
1154
- handle.values as Readonly<Record<string, unknown>>,
1155
- ),
1156
- })}
1157
- >
1158
- <span data-slot="select-value">
1159
- {selectedChoice ? (
1160
- <ChoiceOptionLabel choice={selectedChoice} />
1161
- ) : (
1162
- <span style={{ color: theme.semantic.text.muted }}>
1163
- Choose...
1164
- </span>
1165
- )}
1166
- </span>
1167
- </SelectTrigger>
1168
- <SelectContent
1169
- style={{
1170
- ...themeCssVars,
1171
- fontFamily: theme.typography.fontFamily.body,
1172
- }}
1173
- >
1174
- {choices.map((choice) => (
1175
- <SelectItem
1176
- key={choiceRenderKey(choice)}
1177
- value={choiceRenderKey(choice)}
1178
- textValue={choice.label}
1179
- disabled={choice.disabled}
1180
- {...gameplayActuatorAttributes({
1181
- descriptor,
1182
- draftValues: handle.values as Readonly<Record<string, unknown>>,
1183
- inputKey: input.key,
1184
- intent: "select",
1185
- candidateValue: choice.value,
1186
- candidateState:
1187
- value === choice.value ? "selected" : "unselected",
1188
- enabled: !disabled && !choice.disabled,
1189
- actuatorKind: "click",
1190
- actuatorId: `choice:${input.key}:${choiceRenderKey(choice)}`,
1191
- semanticEffects: gameplayCandidateMetadata({
1192
- descriptor,
1193
- draftValues: handle.values as Readonly<
1194
- Record<string, unknown>
1195
- >,
1196
- inputKey: input.key,
1197
- candidateValue: choice.value,
1198
- intent: "select",
1199
- }).semanticEffects,
1200
- })}
1201
- >
1202
- <ChoiceOptionLabel choice={choice} />
1203
- </SelectItem>
1204
- ))}
1205
- </SelectContent>
1206
- </Select>
1207
- <ChoiceDescription choice={selectedChoice} />
1208
- </FieldFrame>
1209
- );
1210
- }
1211
-
1212
- function ChoiceListField<
1213
- Params extends InteractionParamsShape,
1214
- Key extends keyof Params & string,
1215
- >({
1216
- descriptor,
1217
- handle,
1218
- input,
1219
- value,
1220
- setValue,
1221
- errors,
1222
- missing,
1223
- disabled,
1224
- domain,
1225
- }: InteractionFieldRenderProps<Params, Key> & {
1226
- domain: Extract<InputDomain, { type: "choiceList" }>;
1227
- }) {
1228
- const theme = useTheme();
1229
- const selected = new Set(Array.isArray(value) ? (value as string[]) : []);
1230
- const min =
1231
- domain.selection?.mode === "many"
1232
- ? (domain.selection.min ?? 0)
1233
- : domain.min;
1234
- const max =
1235
- (domain.selection?.mode === "many" ? domain.selection.max : domain.max) ??
1236
- domain.choices?.length ??
1237
- Number.POSITIVE_INFINITY;
1238
- const toggle = (choice: string) => {
1239
- const next = new Set(selected);
1240
- if (next.has(choice)) next.delete(choice);
1241
- else if (next.size < max) next.add(choice);
1242
- setValue([...next] as Params[Key]);
1243
- };
1244
- const meta =
1245
- min || Number.isFinite(max)
1246
- ? `Pick ${min ?? 0}${Number.isFinite(max) ? `-${max}` : "+"}`
1247
- : undefined;
1248
- return (
1249
- <FieldFrame
1250
- label={
1251
- <span
1252
- style={{
1253
- display: "flex",
1254
- justifyContent: "space-between",
1255
- gap: theme.space[2],
1256
- }}
1257
- >
1258
- <span>{labelForInput(input)}</span>
1259
- {meta ? (
1260
- <span style={{ color: theme.semantic.text.muted }}>{meta}</span>
1261
- ) : null}
1262
- </span>
1263
- }
1264
- errors={errors}
1265
- missing={missing}
1266
- >
1267
- <span style={{ display: "flex", flexWrap: "wrap", gap: theme.space[1] }}>
1268
- {(domain.choices ?? []).map((choice) => {
1269
- const value = choice.value as string;
1270
- const checked = selected.has(value);
1271
- const isDisabled =
1272
- disabled || choice.disabled || (!checked && selected.size >= max);
1273
- return (
1274
- <ThemedButton
1275
- key={value}
1276
- type="button"
1277
- variant={checked ? "primary" : "secondary"}
1278
- size="sm"
1279
- disabled={isDisabled}
1280
- aria-pressed={checked}
1281
- title={choice.disabledReason ?? choice.description}
1282
- {...gameplayActuatorAttributes({
1283
- descriptor,
1284
- draftValues: handle.values as Readonly<Record<string, unknown>>,
1285
- inputKey: input.key,
1286
- intent: "toggle",
1287
- candidateValue: value,
1288
- candidateState: checked ? "selected" : "unselected",
1289
- enabled: !isDisabled,
1290
- actuatorKind: "click",
1291
- actuatorId: `choice-list:${input.key}:${value}`,
1292
- semanticEffects: gameplayCandidateMetadata({
1293
- descriptor,
1294
- draftValues: handle.values as Readonly<
1295
- Record<string, unknown>
1296
- >,
1297
- inputKey: input.key,
1298
- candidateValue: value,
1299
- intent: "toggle",
1300
- }).semanticEffects,
1301
- })}
1302
- onClick={() => toggle(value)}
1303
- className="h-8 px-3 text-sm"
1304
- >
1305
- <ChoiceOptionLabel choice={choice} />
1306
- </ThemedButton>
1307
- );
1308
- })}
1309
- </span>
1310
- </FieldFrame>
1311
- );
1312
- }
1313
-
1314
- function ResourceMapField<
1315
- Params extends InteractionParamsShape,
1316
- Key extends keyof Params & string,
1317
- >({
1318
- descriptor,
1319
- handle,
1320
- input,
1321
- value,
1322
- setValue,
1323
- errors,
1324
- missing,
1325
- disabled,
1326
- domain,
1327
- }: InteractionFieldRenderProps<Params, Key> & {
1328
- domain: Extract<InputDomain, { type: "resourceMap" }>;
1329
- }) {
1330
- const theme = useTheme();
1331
- const current: Record<string, unknown> = isRecord(value) ? value : {};
1332
- const update = (
1333
- resourceId: string,
1334
- delta: number,
1335
- min: number,
1336
- max: number,
1337
- ) => {
1338
- const previous = numberOrZero(current[resourceId]);
1339
- const next = Math.max(min, Math.min(max, previous + delta));
1340
- setValue({ ...current, [resourceId]: next } as Params[Key]);
1341
- };
1342
- return (
1343
- <FieldFrame label={labelForInput(input)} errors={errors} missing={missing}>
1344
- <span
1345
- style={{
1346
- display: "grid",
1347
- gridTemplateColumns: "repeat(auto-fit, minmax(140px, 1fr))",
1348
- gap: theme.space[2],
1349
- }}
1350
- >
1351
- {(domain.resources ?? []).map((resource) => {
1352
- const min = resource.min ?? 0;
1353
- const max = resource.max ?? 0;
1354
- const amount = numberOrZero(current[resource.resourceId]);
1355
- return (
1356
- <span
1357
- key={resource.resourceId}
1358
- style={{
1359
- display: "grid",
1360
- gridTemplateColumns: "minmax(0, 1fr) auto auto auto",
1361
- alignItems: "center",
1362
- gap: theme.space[1],
1363
- padding: theme.space[2],
1364
- borderRadius: theme.radius.md,
1365
- background: theme.semantic.surface.inset,
1366
- }}
1367
- >
1368
- <span
1369
- style={{
1370
- minWidth: 0,
1371
- display: "inline-flex",
1372
- alignItems: "center",
1373
- gap: theme.space[1],
1374
- }}
1375
- >
1376
- {resource.icon ? (
1377
- <span aria-hidden style={{ fontSize: "1.1em" }}>
1378
- {resource.icon}
1379
- </span>
1380
- ) : null}
1381
- {resource.label ?? humanize(input.key)}
1382
- </span>
1383
- <StepperButton
1384
- label={`Decrease ${resource.label ?? resource.resourceId}`}
1385
- disabled={disabled || amount <= min}
1386
- browserAttributes={gameplayActuatorAttributes({
1387
- descriptor,
1388
- draftValues: handle.values as Readonly<
1389
- Record<string, unknown>
1390
- >,
1391
- inputKey: input.key,
1392
- intent: "decrement",
1393
- candidateValue: resource.resourceId,
1394
- enabled: !(disabled || amount <= min),
1395
- actuatorKind: "click",
1396
- actuatorId: `resource-decrement:${input.key}:${resource.resourceId}`,
1397
- semanticEffects: gameplayResourceMetadata({
1398
- inputKey: input.key,
1399
- resourceKey: resource.resourceId,
1400
- delta: -1,
1401
- }).semanticEffects,
1402
- })}
1403
- onClick={() => update(resource.resourceId, -1, min, max)}
1404
- >
1405
- -
1406
- </StepperButton>
1407
- <span
1408
- style={{
1409
- minWidth: "2ch",
1410
- textAlign: "center",
1411
- fontVariantNumeric: "tabular-nums",
1412
- }}
1413
- >
1414
- {amount}
1415
- </span>
1416
- <StepperButton
1417
- label={`Increase ${resource.label ?? resource.resourceId}`}
1418
- disabled={disabled || amount >= max}
1419
- browserAttributes={gameplayActuatorAttributes({
1420
- descriptor,
1421
- draftValues: handle.values as Readonly<
1422
- Record<string, unknown>
1423
- >,
1424
- inputKey: input.key,
1425
- intent: "increment",
1426
- candidateValue: resource.resourceId,
1427
- enabled: !(disabled || amount >= max),
1428
- actuatorKind: "click",
1429
- actuatorId: `resource-increment:${input.key}:${resource.resourceId}`,
1430
- semanticEffects: gameplayResourceMetadata({
1431
- inputKey: input.key,
1432
- resourceKey: resource.resourceId,
1433
- delta: 1,
1434
- }).semanticEffects,
1435
- })}
1436
- onClick={() => update(resource.resourceId, 1, min, max)}
1437
- >
1438
- +
1439
- </StepperButton>
1440
- </span>
1441
- );
1442
- })}
1443
- </span>
1444
- </FieldFrame>
1445
- );
1446
- }
1447
-
1448
- function BoundedNumberField<
1449
- Params extends InteractionParamsShape,
1450
- Key extends keyof Params & string,
1451
- >({
1452
- descriptor,
1453
- handle,
1454
- input,
1455
- value,
1456
- setValue,
1457
- errors,
1458
- missing,
1459
- disabled,
1460
- domain,
1461
- }: InteractionFieldRenderProps<Params, Key> & {
1462
- domain: Extract<InputDomain, { type: "boundedNumber" }>;
1463
- }) {
1464
- const theme = useTheme();
1465
- const min = domain.min ?? 0;
1466
- const max = domain.max ?? Number.POSITIVE_INFINITY;
1467
- const step = domain.step ?? 1;
1468
- const current = typeof value === "number" ? value : min;
1469
- const controlId = useId();
1470
- const update = (next: number) =>
1471
- setValue(Math.max(min, Math.min(max, next)) as Params[Key]);
1472
- return (
1473
- <FieldFrame
1474
- label={labelForInput(input)}
1475
- controlId={controlId}
1476
- errors={errors}
1477
- missing={missing}
1478
- >
1479
- <span
1480
- style={{
1481
- display: "inline-flex",
1482
- alignItems: "center",
1483
- gap: theme.space[1],
1484
- }}
1485
- >
1486
- <StepperButton
1487
- label={`Decrease ${input.key}`}
1488
- disabled={disabled || current <= min}
1489
- browserAttributes={gameplayActuatorAttributes({
1490
- descriptor,
1491
- draftValues: handle.values as Readonly<Record<string, unknown>>,
1492
- inputKey: input.key,
1493
- intent: "decrement",
1494
- enabled: !(disabled || current <= min),
1495
- actuatorKind: "click",
1496
- actuatorId: `bounded-decrement:${input.key}`,
1497
- semanticEffects: gameplayScalarStepMetadata({
1498
- inputKey: input.key,
1499
- value: Math.max(min, Math.min(max, current - step)),
1500
- }).semanticEffects,
1501
- })}
1502
- onClick={() => update(current - step)}
1503
- >
1504
- -
1505
- </StepperButton>
1506
- <Input
1507
- id={controlId}
1508
- type="number"
1509
- min={min}
1510
- max={Number.isFinite(max) ? max : undefined}
1511
- step={step}
1512
- value={current}
1513
- disabled={disabled}
1514
- {...gameplayActuatorAttributes({
1515
- descriptor,
1516
- draftValues: handle.values as Readonly<Record<string, unknown>>,
1517
- inputKey: input.key,
1518
- intent: "fill",
1519
- enabled: !disabled,
1520
- actuatorKind: "fill",
1521
- actuatorId: `bounded-fill:${input.key}`,
1522
- acceptedEffectPatterns: gameplayScalarFillMetadata({
1523
- inputKey: input.key,
1524
- domain,
1525
- }).acceptedEffectPatterns,
1526
- })}
1527
- onChange={(event) => update(Number(event.target.value))}
1528
- className="h-9 w-[8ch] px-2 text-center text-sm md:text-sm"
1529
- />
1530
- <StepperButton
1531
- label={`Increase ${input.key}`}
1532
- disabled={disabled || current >= max}
1533
- browserAttributes={gameplayActuatorAttributes({
1534
- descriptor,
1535
- draftValues: handle.values as Readonly<Record<string, unknown>>,
1536
- inputKey: input.key,
1537
- intent: "increment",
1538
- enabled: !(disabled || current >= max),
1539
- actuatorKind: "click",
1540
- actuatorId: `bounded-increment:${input.key}`,
1541
- semanticEffects: gameplayScalarStepMetadata({
1542
- inputKey: input.key,
1543
- value: Math.max(min, Math.min(max, current + step)),
1544
- }).semanticEffects,
1545
- })}
1546
- onClick={() => update(current + step)}
1547
- >
1548
- +
1549
- </StepperButton>
1550
- </span>
1551
- </FieldFrame>
1552
- );
1553
- }
1554
-
1555
- function TargetSummaryField<
1556
- Params extends InteractionParamsShape,
1557
- Key extends keyof Params & string,
1558
- >({
1559
- input,
1560
- value,
1561
- errors,
1562
- missing,
1563
- domain,
1564
- }: InteractionFieldRenderProps<Params, Key> & {
1565
- domain: Extract<InputDomain, { type: "cardTarget" | "boardTarget" }>;
1566
- }) {
1567
- const target = inputTargetKind(domain) ?? "target";
1568
- return (
1569
- <FieldFrame label={labelForInput(input)} errors={errors} missing={missing}>
1570
- <span>
1571
- {Array.isArray(value)
1572
- ? value.length > 0
1573
- ? `${value.length} selected: ${value.join(", ")}`
1574
- : `Select ${targetSelectionLabel(domain)}.`
1575
- : typeof value === "string"
1576
- ? value
1577
- : `Select a ${target} on the board.`}
1578
- </span>
1579
- </FieldFrame>
1580
- );
1581
- }
1582
-
1583
- function targetSelectionLabel(domain: InputDomain): string {
1584
- const target = inputTargetKind(domain) ?? "target";
1585
- const selection = isTargetDomain(domain) ? domain.selection : undefined;
1586
- if (selection?.mode !== "many") return `a ${target}`;
1587
- const min = selection.min ?? 0;
1588
- if (selection.max !== undefined && min === selection.max) {
1589
- return `${min} ${target}${min === 1 ? "" : "s"}`;
1590
- }
1591
- return `${min}${selection.max ? `-${selection.max}` : "+"} ${target}s`;
1592
- }
1593
-
1594
- function StepperButton({
1595
- label,
1596
- disabled,
1597
- browserAttributes,
1598
- onClick,
1599
- children,
1600
- }: {
1601
- label: string;
1602
- disabled: boolean;
1603
- browserAttributes?: BrowserInteractionAttributeMap;
1604
- onClick: () => void;
1605
- children: ReactNode;
1606
- }) {
1607
- return (
1608
- <ThemedButton
1609
- type="button"
1610
- variant="secondary"
1611
- size="sm"
1612
- aria-label={label}
1613
- disabled={disabled}
1614
- {...browserAttributes}
1615
- onClick={onClick}
1616
- className="h-8 w-8 text-sm"
1617
- >
1618
- {children}
1619
- </ThemedButton>
1620
- );
1621
- }
1622
-
1623
- function labelForInput(input: InteractionInputDescriptor): string {
1624
- if (input.domain.type === "choice") {
1625
- const exact = input.domain.choices?.find(
1626
- (choice) => choice.value === input.defaultValue,
1627
- );
1628
- if (exact?.label && input.key === exact.value) return exact.label;
1629
- }
1630
- return humanize(input.key);
1631
- }
1632
-
1633
- function humanize(key: string): string {
1634
- return key
1635
- .replace(/Id$/, "")
1636
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
1637
- .replace(/[-_]+/g, " ")
1638
- .replace(/\b\w/g, (letter) => letter.toUpperCase());
1639
- }
1640
-
1641
- function isRecord(value: unknown): value is Record<string, unknown> {
1642
- return typeof value === "object" && value !== null && !Array.isArray(value);
1643
- }
1644
-
1645
- function numberOrZero(value: unknown): number {
1646
- return typeof value === "number" && Number.isFinite(value) ? value : 0;
1647
- }