@cntrl-site/sdk-nextjs 1.8.9-alpha.0 → 1.8.9-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.
@@ -109,16 +109,15 @@ class InteractionsRegistry {
109
109
  const timestamp = Date.now();
110
110
  for (const interaction of this.interactions) {
111
111
  const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
112
- const matchingTrigger = interaction.triggers.find((trigger) => 'position' in trigger && (trigger.position < position ? trigger.from : trigger.to) === currentStateId);
112
+ const matchingTrigger = interaction.triggers.find((trigger) => 'position' in trigger && (trigger.position < position ? trigger.from : trigger.to) === currentStateId // refactor
113
+ );
113
114
  if (!matchingTrigger || !('position' in matchingTrigger))
114
115
  continue;
115
116
  const activeStateId = this.getActiveInteractionState(interaction.id);
116
- const targetStateId = matchingTrigger.isReverse && matchingTrigger.position > position
117
- ? matchingTrigger.from
118
- : matchingTrigger.to;
117
+ const targetStateId = matchingTrigger.position > position ? matchingTrigger.from : matchingTrigger.to;
119
118
  const isNewStateActive = targetStateId === activeStateId;
120
119
  this.setCurrentStateForInteraction(interaction.id, targetStateId !== null && targetStateId !== void 0 ? targetStateId : activeStateId);
121
- const transitioningItems = (_a = this.stateItemsIdsMap[targetStateId]) !== null && _a !== void 0 ? _a : [];
120
+ const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
122
121
  const state = interaction.states.find((state) => state.id === targetStateId);
123
122
  const actions = (_b = state === null || state === void 0 ? void 0 : state.actions) !== null && _b !== void 0 ? _b : [];
124
123
  for (const action of actions) {
@@ -127,7 +126,7 @@ class InteractionsRegistry {
127
126
  continue;
128
127
  ctrl.receiveAction(action.type);
129
128
  }
130
- this.itemsStages = this.itemsStages.map((stage) => {
129
+ const itemsStages = this.itemsStages.map((stage) => {
131
130
  if (stage.interactionId !== interaction.id)
132
131
  return stage;
133
132
  return {
@@ -140,6 +139,7 @@ class InteractionsRegistry {
140
139
  updated: timestamp
141
140
  };
142
141
  });
142
+ this.itemsStages = itemsStages;
143
143
  const itemsToNotify = new Set(transitioningItems);
144
144
  for (const trigger of interaction.triggers) {
145
145
  if (!('itemId' in trigger))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.8.9-alpha.0",
3
+ "version": "1.8.9-alpha.1",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -117,16 +117,14 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
117
117
  for (const interaction of this.interactions) {
118
118
  const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
119
119
  const matchingTrigger = interaction.triggers.find((trigger) =>
120
- 'position' in trigger && (trigger.position < position ? trigger.from : trigger.to) === currentStateId
120
+ 'position' in trigger && (trigger.position < position ? trigger.from : trigger.to) === currentStateId // refactor
121
121
  );
122
122
  if (!matchingTrigger || !('position' in matchingTrigger)) continue;
123
123
  const activeStateId = this.getActiveInteractionState(interaction.id);
124
- const targetStateId = matchingTrigger.isReverse && matchingTrigger.position > position
125
- ? matchingTrigger.from
126
- : matchingTrigger.to;
124
+ const targetStateId = matchingTrigger.position > position ? matchingTrigger.from : matchingTrigger.to;
127
125
  const isNewStateActive = targetStateId === activeStateId;
128
126
  this.setCurrentStateForInteraction(interaction.id, targetStateId ?? activeStateId);
129
- const transitioningItems = this.stateItemsIdsMap[targetStateId] ?? [];
127
+ const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
130
128
  const state = interaction.states.find((state) => state.id === targetStateId);
131
129
  const actions = state?.actions ?? [];
132
130
  for (const action of actions) {
@@ -134,18 +132,19 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
134
132
  if (!ctrl) continue;
135
133
  ctrl.receiveAction(action.type);
136
134
  }
137
- this.itemsStages = this.itemsStages.map((stage) => {
135
+ const itemsStages = this.itemsStages.map((stage) => {
138
136
  if (stage.interactionId !== interaction.id) return stage;
139
137
  return {
140
138
  itemId: stage.itemId,
141
139
  interactionId: stage.interactionId,
142
- type: 'transitioning',
140
+ type: 'transitioning' as const,
143
141
  from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
144
142
  to: targetStateId,
145
- direction: isNewStateActive ? 'in' : 'out',
143
+ direction: isNewStateActive ? 'in' as const : 'out' as const,
146
144
  updated: timestamp
147
145
  };
148
146
  });
147
+ this.itemsStages = itemsStages;
149
148
  const itemsToNotify = new Set<ItemId>(transitioningItems);
150
149
  for (const trigger of interaction.triggers) {
151
150
  if (!('itemId' in trigger)) continue;