@cntrl-site/sdk-nextjs 1.9.13-4 → 1.9.13-5

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.
@@ -106,44 +106,47 @@ class InteractionsRegistry {
106
106
  return available;
107
107
  }
108
108
  notifyLoad() {
109
- // const timestamp = Date.now();
110
- // for (const interaction of this.interactions) {
111
- // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
112
- // const matchingTrigger = interaction.triggers.find(trigger =>
113
- // 'position' in trigger && trigger.position === 0 && trigger.from === currentStateId
114
- // );
115
- // if (!matchingTrigger) continue;
116
- // const activeStateId = this.getActiveInteractionState(interaction.id);
117
- // const isNewStateActive = matchingTrigger.to === activeStateId;
118
- // this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
119
- // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
120
- // const state = interaction.states.find((state) => state.id === matchingTrigger.to);
121
- // const actions = state?.actions ?? [];
122
- // for (const action of actions) {
123
- // const ctrl = this.ctrls.get(action.itemId);
124
- // if (!ctrl) continue;
125
- // ctrl.receiveAction(action.type);
126
- // }
127
- // this.itemsStages = this.itemsStages.map((stage) => {
128
- // if (stage.interactionId !== interaction.id) return stage;
129
- // return {
130
- // itemId: stage.itemId,
131
- // interactionId: stage.interactionId,
132
- // type: 'transitioning',
133
- // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
134
- // to: matchingTrigger.to,
135
- // direction: isNewStateActive ? 'in' : 'out',
136
- // updated: timestamp
137
- // };
138
- // });
139
- // const itemsToNotify = new Set<ItemId>(transitioningItems);
140
- // for (const trigger of interaction.triggers) {
141
- // if (!('itemId' in trigger)) continue;
142
- // itemsToNotify.add(trigger.itemId);
143
- // }
144
- // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
145
- // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
146
- // }
109
+ var _a, _b;
110
+ const timestamp = Date.now();
111
+ for (const interaction of this.interactions) {
112
+ const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
113
+ const matchingTrigger = interaction.triggers.find(trigger => 'position' in trigger && trigger.position === 0 && trigger.from === currentStateId);
114
+ if (!matchingTrigger)
115
+ continue;
116
+ const activeStateId = this.getActiveInteractionState(interaction.id);
117
+ const isNewStateActive = matchingTrigger.to === activeStateId;
118
+ this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
119
+ const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
120
+ const state = interaction.states.find((state) => state.id === matchingTrigger.to);
121
+ const actions = (_b = state === null || state === void 0 ? void 0 : state.actions) !== null && _b !== void 0 ? _b : [];
122
+ for (const action of actions) {
123
+ const ctrl = this.ctrls.get(action.itemId);
124
+ if (!ctrl)
125
+ continue;
126
+ ctrl.receiveAction(action.type);
127
+ }
128
+ this.itemsStages = this.itemsStages.map((stage) => {
129
+ if (stage.interactionId !== interaction.id)
130
+ return stage;
131
+ return {
132
+ itemId: stage.itemId,
133
+ interactionId: stage.interactionId,
134
+ type: 'transitioning',
135
+ from: stage.type === 'transitioning' ? stage.to : stage.stateId,
136
+ to: matchingTrigger.to,
137
+ direction: isNewStateActive ? 'in' : 'out',
138
+ updated: timestamp
139
+ };
140
+ });
141
+ const itemsToNotify = new Set(transitioningItems);
142
+ for (const trigger of interaction.triggers) {
143
+ if (!('itemId' in trigger))
144
+ continue;
145
+ itemsToNotify.add(trigger.itemId);
146
+ }
147
+ this.notifyItemCtrlsChange(Array.from(itemsToNotify));
148
+ this.notifyTransitionStartForItems(transitioningItems, activeStateId);
149
+ }
147
150
  }
148
151
  notifyScroll(position) {
149
152
  var _a, _b, _c;
@@ -204,47 +207,50 @@ class InteractionsRegistry {
204
207
  }
205
208
  }
206
209
  notifyItemTrigger(itemId, triggerType) {
207
- // const timestamp = Date.now();
208
- // for (const interaction of this.interactions) {
209
- // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
210
- // const matchingTrigger = interaction.triggers.find((trigger) =>
211
- // 'triggerEvent' in trigger
212
- // && trigger.itemId === itemId
213
- // && trigger.from === currentStateId
214
- // && trigger.triggerEvent === triggerType
215
- // );
216
- // if (!matchingTrigger) continue;
217
- // const activeStateId = this.getActiveInteractionState(interaction.id);
218
- // const isNewStateActive = matchingTrigger.to === activeStateId;
219
- // this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
220
- // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
221
- // const state = interaction.states.find((state) => state.id === matchingTrigger.to);
222
- // const actions = state?.actions ?? [];
223
- // for (const action of actions) {
224
- // const ctrl = this.ctrls.get(action.itemId);
225
- // if (!ctrl) continue;
226
- // ctrl.receiveAction(action.type);
227
- // }
228
- // this.itemsStages = this.itemsStages.map((stage) => {
229
- // if (stage.interactionId !== interaction.id) return stage;
230
- // return {
231
- // itemId: stage.itemId,
232
- // interactionId: stage.interactionId,
233
- // type: 'transitioning',
234
- // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
235
- // to: matchingTrigger.to,
236
- // direction: isNewStateActive ? 'in' : 'out',
237
- // updated: timestamp
238
- // };
239
- // });
240
- // const itemsToNotify = new Set<ItemId>(transitioningItems);
241
- // for (const trigger of interaction.triggers) {
242
- // if (!('itemId' in trigger)) continue;
243
- // itemsToNotify.add(trigger.itemId);
244
- // }
245
- // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
246
- // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
247
- // }
210
+ var _a, _b;
211
+ const timestamp = Date.now();
212
+ for (const interaction of this.interactions) {
213
+ const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
214
+ const matchingTrigger = interaction.triggers.find((trigger) => 'triggerEvent' in trigger
215
+ && trigger.itemId === itemId
216
+ && trigger.from === currentStateId
217
+ && trigger.triggerEvent === triggerType);
218
+ if (!matchingTrigger)
219
+ continue;
220
+ const activeStateId = this.getActiveInteractionState(interaction.id);
221
+ const isNewStateActive = matchingTrigger.to === activeStateId;
222
+ this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
223
+ const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
224
+ const state = interaction.states.find((state) => state.id === matchingTrigger.to);
225
+ const actions = (_b = state === null || state === void 0 ? void 0 : state.actions) !== null && _b !== void 0 ? _b : [];
226
+ for (const action of actions) {
227
+ const ctrl = this.ctrls.get(action.itemId);
228
+ if (!ctrl)
229
+ continue;
230
+ ctrl.receiveAction(action.type);
231
+ }
232
+ this.itemsStages = this.itemsStages.map((stage) => {
233
+ if (stage.interactionId !== interaction.id)
234
+ return stage;
235
+ return {
236
+ itemId: stage.itemId,
237
+ interactionId: stage.interactionId,
238
+ type: 'transitioning',
239
+ from: stage.type === 'transitioning' ? stage.to : stage.stateId,
240
+ to: matchingTrigger.to,
241
+ direction: isNewStateActive ? 'in' : 'out',
242
+ updated: timestamp
243
+ };
244
+ });
245
+ const itemsToNotify = new Set(transitioningItems);
246
+ for (const trigger of interaction.triggers) {
247
+ if (!('itemId' in trigger))
248
+ continue;
249
+ itemsToNotify.add(trigger.itemId);
250
+ }
251
+ this.notifyItemCtrlsChange(Array.from(itemsToNotify));
252
+ this.notifyTransitionStartForItems(transitioningItems, activeStateId);
253
+ }
248
254
  }
249
255
  notifyTransitionStartForItems(itemsIds, activeStateId) {
250
256
  var _a, _b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.13-4",
3
+ "version": "1.9.13-5",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -115,46 +115,46 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
115
115
  }
116
116
 
117
117
  notifyLoad() {
118
- // const timestamp = Date.now();
119
- // for (const interaction of this.interactions) {
120
- // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
121
- // const matchingTrigger = interaction.triggers.find(trigger =>
122
- // 'position' in trigger && trigger.position === 0 && trigger.from === currentStateId
123
- // );
124
- // if (!matchingTrigger) continue;
125
- // const activeStateId = this.getActiveInteractionState(interaction.id);
126
- // const isNewStateActive = matchingTrigger.to === activeStateId;
127
- // this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
128
- // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
129
- // const state = interaction.states.find((state) => state.id === matchingTrigger.to);
130
- // const actions = state?.actions ?? [];
131
- // for (const action of actions) {
132
- // const ctrl = this.ctrls.get(action.itemId);
133
- // if (!ctrl) continue;
134
- // ctrl.receiveAction(action.type);
135
- // }
118
+ const timestamp = Date.now();
119
+ for (const interaction of this.interactions) {
120
+ const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
121
+ const matchingTrigger = interaction.triggers.find(trigger =>
122
+ 'position' in trigger && trigger.position === 0 && trigger.from === currentStateId
123
+ );
124
+ if (!matchingTrigger) continue;
125
+ const activeStateId = this.getActiveInteractionState(interaction.id);
126
+ const isNewStateActive = matchingTrigger.to === activeStateId;
127
+ this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
128
+ const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
129
+ const state = interaction.states.find((state) => state.id === matchingTrigger.to);
130
+ const actions = state?.actions ?? [];
131
+ for (const action of actions) {
132
+ const ctrl = this.ctrls.get(action.itemId);
133
+ if (!ctrl) continue;
134
+ ctrl.receiveAction(action.type);
135
+ }
136
136
 
137
- // this.itemsStages = this.itemsStages.map((stage) => {
138
- // if (stage.interactionId !== interaction.id) return stage;
139
- // return {
140
- // itemId: stage.itemId,
141
- // interactionId: stage.interactionId,
142
- // type: 'transitioning',
143
- // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
144
- // to: matchingTrigger.to,
145
- // direction: isNewStateActive ? 'in' : 'out',
146
- // updated: timestamp
147
- // };
148
- // });
137
+ this.itemsStages = this.itemsStages.map((stage) => {
138
+ if (stage.interactionId !== interaction.id) return stage;
139
+ return {
140
+ itemId: stage.itemId,
141
+ interactionId: stage.interactionId,
142
+ type: 'transitioning',
143
+ from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
144
+ to: matchingTrigger.to,
145
+ direction: isNewStateActive ? 'in' : 'out',
146
+ updated: timestamp
147
+ };
148
+ });
149
149
 
150
- // const itemsToNotify = new Set<ItemId>(transitioningItems);
151
- // for (const trigger of interaction.triggers) {
152
- // if (!('itemId' in trigger)) continue;
153
- // itemsToNotify.add(trigger.itemId);
154
- // }
155
- // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
156
- // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
157
- // }
150
+ const itemsToNotify = new Set<ItemId>(transitioningItems);
151
+ for (const trigger of interaction.triggers) {
152
+ if (!('itemId' in trigger)) continue;
153
+ itemsToNotify.add(trigger.itemId);
154
+ }
155
+ this.notifyItemCtrlsChange(Array.from(itemsToNotify));
156
+ this.notifyTransitionStartForItems(transitioningItems, activeStateId);
157
+ }
158
158
  }
159
159
 
160
160
  notifyScroll(position: number) {
@@ -210,47 +210,47 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
210
210
  }
211
211
 
212
212
  notifyItemTrigger(itemId: string, triggerType: TriggerType): void {
213
- // const timestamp = Date.now();
214
- // for (const interaction of this.interactions) {
215
- // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
216
- // const matchingTrigger = interaction.triggers.find((trigger) =>
217
- // 'triggerEvent' in trigger
218
- // && trigger.itemId === itemId
219
- // && trigger.from === currentStateId
220
- // && trigger.triggerEvent === triggerType
221
- // );
222
- // if (!matchingTrigger) continue;
223
- // const activeStateId = this.getActiveInteractionState(interaction.id);
224
- // const isNewStateActive = matchingTrigger.to === activeStateId;
225
- // this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
226
- // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
227
- // const state = interaction.states.find((state) => state.id === matchingTrigger.to);
228
- // const actions = state?.actions ?? [];
229
- // for (const action of actions) {
230
- // const ctrl = this.ctrls.get(action.itemId);
231
- // if (!ctrl) continue;
232
- // ctrl.receiveAction(action.type);
233
- // }
234
- // this.itemsStages = this.itemsStages.map((stage) => {
235
- // if (stage.interactionId !== interaction.id) return stage;
236
- // return {
237
- // itemId: stage.itemId,
238
- // interactionId: stage.interactionId,
239
- // type: 'transitioning',
240
- // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
241
- // to: matchingTrigger.to,
242
- // direction: isNewStateActive ? 'in' : 'out',
243
- // updated: timestamp
244
- // };
245
- // });
246
- // const itemsToNotify = new Set<ItemId>(transitioningItems);
247
- // for (const trigger of interaction.triggers) {
248
- // if (!('itemId' in trigger)) continue;
249
- // itemsToNotify.add(trigger.itemId);
250
- // }
251
- // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
252
- // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
253
- // }
213
+ const timestamp = Date.now();
214
+ for (const interaction of this.interactions) {
215
+ const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
216
+ const matchingTrigger = interaction.triggers.find((trigger) =>
217
+ 'triggerEvent' in trigger
218
+ && trigger.itemId === itemId
219
+ && trigger.from === currentStateId
220
+ && trigger.triggerEvent === triggerType
221
+ );
222
+ if (!matchingTrigger) continue;
223
+ const activeStateId = this.getActiveInteractionState(interaction.id);
224
+ const isNewStateActive = matchingTrigger.to === activeStateId;
225
+ this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
226
+ const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
227
+ const state = interaction.states.find((state) => state.id === matchingTrigger.to);
228
+ const actions = state?.actions ?? [];
229
+ for (const action of actions) {
230
+ const ctrl = this.ctrls.get(action.itemId);
231
+ if (!ctrl) continue;
232
+ ctrl.receiveAction(action.type);
233
+ }
234
+ this.itemsStages = this.itemsStages.map((stage) => {
235
+ if (stage.interactionId !== interaction.id) return stage;
236
+ return {
237
+ itemId: stage.itemId,
238
+ interactionId: stage.interactionId,
239
+ type: 'transitioning',
240
+ from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
241
+ to: matchingTrigger.to,
242
+ direction: isNewStateActive ? 'in' : 'out',
243
+ updated: timestamp
244
+ };
245
+ });
246
+ const itemsToNotify = new Set<ItemId>(transitioningItems);
247
+ for (const trigger of interaction.triggers) {
248
+ if (!('itemId' in trigger)) continue;
249
+ itemsToNotify.add(trigger.itemId);
250
+ }
251
+ this.notifyItemCtrlsChange(Array.from(itemsToNotify));
252
+ this.notifyTransitionStartForItems(transitioningItems, activeStateId);
253
+ }
254
254
  }
255
255
 
256
256
  notifyTransitionStartForItems(itemsIds: string[], activeStateId: string) {