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