@dreamboard-games/sdk 0.5.0-alpha.34 → 0.5.0-alpha.36

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.
@@ -1498,6 +1498,19 @@ function inputDomainErrors(domain, value, selection, options = {}) {
1498
1498
  function inputValueInDomain(domain, value, selection, options = {}) {
1499
1499
  return inputDomainErrors(domain, value, selection, options).length === 0;
1500
1500
  }
1501
+ function canonicalizeInputSelection(value, selection, domain) {
1502
+ if (selection?.mode !== "many") return value;
1503
+ if (!Array.isArray(value)) return value;
1504
+ const values = value;
1505
+ const choices = domain?.type === "cardTarget" || domain?.type === "tileTarget" || domain?.type === "boardTarget" ? domain.eligibleTargets : domain?.type === "choice" ? domain.choices.map((choice) => choice.value) : [];
1506
+ const positions = /* @__PURE__ */ new Map();
1507
+ choices.forEach(
1508
+ (choice, index) => positions.set(inputValueKey(choice), index)
1509
+ );
1510
+ return values.map((item) => ({ item, key: inputValueKey(item) })).sort(
1511
+ (a, b) => (positions.get(a.key) ?? choices.length) - (positions.get(b.key) ?? choices.length) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
1512
+ ).map(({ item }) => item);
1513
+ }
1501
1514
  function inputTargetInDomain(domain, value) {
1502
1515
  switch (domain.type) {
1503
1516
  case "choice":
@@ -1545,7 +1558,14 @@ function inputValueKey(value) {
1545
1558
  case "undefined":
1546
1559
  return `${typeof value}:${String(value)}`;
1547
1560
  default:
1548
- return `json:${JSON.stringify(value)}`;
1561
+ return `json:${JSON.stringify(value, (_key, item) => {
1562
+ if (item === null || typeof item !== "object" || Array.isArray(item))
1563
+ return item;
1564
+ const record3 = item;
1565
+ return Object.fromEntries(
1566
+ Object.keys(record3).sort().map((key) => [key, record3[key]])
1567
+ );
1568
+ })}`;
1549
1569
  }
1550
1570
  }
1551
1571
  function pluralize(word, count) {
@@ -1596,7 +1616,8 @@ export {
1596
1616
  sameBoardSpaceTarget,
1597
1617
  inputDomainErrors,
1598
1618
  inputValueInDomain,
1619
+ canonicalizeInputSelection,
1599
1620
  inputTargetInDomain,
1600
1621
  inputValueKey
1601
1622
  };
1602
- //# sourceMappingURL=chunk-CZRPUWCT.js.map
1623
+ //# sourceMappingURL=chunk-7GX27XU6.js.map