@realnation/builder-shared-sdk 2.1.0 → 2.3.0

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.
@@ -19,6 +19,17 @@ export interface UseInteractionStateOptions {
19
19
  */
20
20
  keys?: StyleKeyCase;
21
21
  }
22
+ export interface InteractionBindOptions {
23
+ /**
24
+ * Makes Click behave like a radio group instead of an independent toggle:
25
+ * picking one clears the others, and clicking the picked one keeps it picked.
26
+ *
27
+ * Single-choice answers need this. Without it a player who picks A and then B
28
+ * leaves both looking chosen, which is worse than no feedback at all.
29
+ * Ignored by the other triggers, where a transient state has no siblings.
30
+ */
31
+ group?: string;
32
+ }
22
33
  export interface InteractionStateApi {
23
34
  /**
24
35
  * The style to merge onto an element.
@@ -28,7 +39,7 @@ export interface InteractionStateApi {
28
39
  */
29
40
  style(property: InteractionProperty | null | undefined, key: string, active?: boolean): InteractionStyle;
30
41
  /** Event handlers to v-bind. Empty unless the trigger is Hover / Press or Click. */
31
- bind(property: InteractionProperty | null | undefined, key: string): Record<string, () => void>;
42
+ bind(property: InteractionProperty | null | undefined, key: string, options?: InteractionBindOptions): Record<string, () => void>;
32
43
  /**
33
44
  * Restarts the timed triggers for exactly these elements.
34
45
  *
@@ -1 +1 @@
1
- {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../src/interaction/vue.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtF,wFAAwF;AACxF,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,WAAW,0BAA0B;IACzC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,UA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,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,8EAA8E;IAC9E,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IACrC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACzG,oFAAoF;IACpF,IAAI,CACF,QAAQ,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,EAChD,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;IAC9B;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACxC,oEAAoE;IACpE,IAAI,IAAI,IAAI,CAAC;IACb,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAAC;CAC3C;AAUD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,mBAAmB,CAyGjG"}
@@ -35,12 +35,15 @@ export function useInteractionState(options = {}) {
35
35
  // for its first frame; one boolean cannot say both things.
36
36
  const instant = reactive({});
37
37
  const timers = new Map();
38
+ // Which group each key belongs to, so a radio click knows whom to clear.
39
+ const groups = new Map();
38
40
  // Guards the deferred On Appear callback: by the time the frame lands the
39
41
  // player may already have navigated on, and the element is gone.
40
42
  let generation = 0;
41
43
  const stop = () => {
42
44
  timers.forEach((handle) => clearTimer(handle));
43
45
  timers.clear();
46
+ groups.clear();
44
47
  generation += 1;
45
48
  };
46
49
  const api = {
@@ -54,14 +57,30 @@ export function useInteractionState(options = {}) {
54
57
  selfDriven: forced !== undefined,
55
58
  });
56
59
  },
57
- bind(property, key) {
60
+ bind(property, key, bindOptions = {}) {
58
61
  if (!isInteractionEnabled(property))
59
62
  return {};
60
63
  const trigger = interactionTriggerOf(property);
61
64
  if (trigger === 'click') {
65
+ const group = bindOptions.group;
66
+ if (group)
67
+ groups.set(key, group);
62
68
  // Deliberately not stopping propagation: the element may also carry a
63
- // link or a node connection, and the visual state is only a layer on top.
64
- return { onClick: () => { active[key] = !active[key]; } };
69
+ // link, a node connection, or the game's own answer handler, and the
70
+ // visual state is only a layer on top of whatever else happens.
71
+ return {
72
+ onClick: () => {
73
+ if (!group) {
74
+ active[key] = !active[key];
75
+ return;
76
+ }
77
+ groups.forEach((g, k) => {
78
+ if (g === group && k !== key)
79
+ active[k] = false;
80
+ });
81
+ active[key] = true;
82
+ },
83
+ };
65
84
  }
66
85
  if (trigger !== 'hover')
67
86
  return {};
@@ -96,7 +115,11 @@ export function useInteractionState(options = {}) {
96
115
  active[key] = false;
97
116
  timers.set(key, setTimer(() => { active[key] = !active[key]; }, interactionPeriodOf(property)));
98
117
  }
99
- else {
118
+ else if (trigger !== 'click') {
119
+ // Click is a state the player put the element into on purpose (which
120
+ // answer they picked). Navigating to another page and back re-syncs
121
+ // the timed triggers, and clearing their choice on the way would be
122
+ // a bug. Hover has no such meaning: the pointer really has left.
100
123
  active[key] = false;
101
124
  }
102
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realnation/builder-shared-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "exports": {