@cntrl-site/sdk-nextjs 1.9.13-1 → 1.9.13-3

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.
@@ -148,106 +148,96 @@ class InteractionsRegistry {
148
148
  }
149
149
  }
150
150
  notifyScroll(position) {
151
- var _a, _b, _c;
152
- const timestamp = Date.now();
153
- for (const interaction of this.interactions) {
154
- const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
155
- const activeStateId = (_a = interaction.states.find((state) => state.id !== interaction.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
156
- const matchingTrigger = interaction.triggers.find((trigger) => {
157
- if (!('position' in trigger) || trigger.position === 0)
158
- return false;
159
- const triggerPosition = trigger.position * window.innerWidth;
160
- const isScrolledPastTrigger = triggerPosition < position;
161
- if (!isScrolledPastTrigger && !trigger.isReverse)
162
- return false;
163
- const stateId = isScrolledPastTrigger ? trigger.from : trigger.to;
164
- return stateId === currentStateId;
165
- });
166
- if (!matchingTrigger || !('position' in matchingTrigger) || !activeStateId)
167
- continue;
168
- const triggerPosition = matchingTrigger.position * window.innerWidth;
169
- const isScrolledPastTrigger = triggerPosition < position;
170
- const targetStateId = isScrolledPastTrigger ? matchingTrigger.to : matchingTrigger.from;
171
- this.setCurrentStateForInteraction(interaction.id, targetStateId);
172
- const transitioningItems = (_b = this.stateItemsIdsMap[activeStateId]) !== null && _b !== void 0 ? _b : [];
173
- const state = interaction.states.find((state) => state.id === targetStateId);
174
- const actions = (_c = state === null || state === void 0 ? void 0 : state.actions) !== null && _c !== void 0 ? _c : [];
175
- for (const action of actions) {
176
- const ctrl = this.ctrls.get(action.itemId);
177
- if (!ctrl)
178
- continue;
179
- ctrl.receiveAction(action.type);
180
- }
181
- const itemsStages = this.itemsStages.map((stage) => {
182
- if (stage.interactionId !== interaction.id)
183
- return stage;
184
- const newStage = {
185
- itemId: stage.itemId,
186
- interactionId: stage.interactionId,
187
- type: 'transitioning',
188
- from: stage.type === 'transitioning' ? stage.to : stage.stateId,
189
- to: targetStateId,
190
- direction: targetStateId === activeStateId ? 'in' : 'out',
191
- updated: timestamp
192
- };
193
- return newStage;
194
- });
195
- this.itemsStages = itemsStages;
196
- const itemsToNotify = new Set(transitioningItems);
197
- for (const trigger of interaction.triggers) {
198
- if (!('itemId' in trigger))
199
- continue;
200
- itemsToNotify.add(trigger.itemId);
201
- }
202
- this.notifyItemCtrlsChange(Array.from(itemsToNotify));
203
- this.notifyTransitionStartForItems(transitioningItems, activeStateId);
204
- }
151
+ // const timestamp = Date.now();
152
+ // for (const interaction of this.interactions) {
153
+ // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
154
+ // const activeStateId = interaction.states.find((state) => state.id !== interaction.startStateId)?.id;
155
+ // const matchingTrigger = interaction.triggers.find((trigger) => {
156
+ // if (!('position' in trigger) || trigger.position === 0) return false;
157
+ // const triggerPosition = trigger.position * window.innerWidth;
158
+ // const isScrolledPastTrigger = triggerPosition < position;
159
+ // if (!isScrolledPastTrigger && !trigger.isReverse) return false;
160
+ // const stateId = isScrolledPastTrigger ? trigger.from : trigger.to;
161
+ // return stateId === currentStateId;
162
+ // });
163
+ // if (!matchingTrigger || !('position' in matchingTrigger) || !activeStateId) continue;
164
+ // const triggerPosition = matchingTrigger.position * window.innerWidth;
165
+ // const isScrolledPastTrigger = triggerPosition < position;
166
+ // const targetStateId = isScrolledPastTrigger ? matchingTrigger.to : matchingTrigger.from;
167
+ // this.setCurrentStateForInteraction(interaction.id, targetStateId);
168
+ // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
169
+ // const state = interaction.states.find((state) => state.id === targetStateId);
170
+ // const actions = state?.actions ?? [];
171
+ // for (const action of actions) {
172
+ // const ctrl = this.ctrls.get(action.itemId);
173
+ // if (!ctrl) continue;
174
+ // ctrl.receiveAction(action.type);
175
+ // }
176
+ // const itemsStages = this.itemsStages.map((stage) => {
177
+ // if (stage.interactionId !== interaction.id) return stage;
178
+ // const newStage = {
179
+ // itemId: stage.itemId,
180
+ // interactionId: stage.interactionId,
181
+ // type: 'transitioning' as const,
182
+ // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
183
+ // to: targetStateId,
184
+ // direction: targetStateId === activeStateId ? 'in' as const : 'out' as const,
185
+ // updated: timestamp
186
+ // };
187
+ // return newStage;
188
+ // });
189
+ // this.itemsStages = itemsStages;
190
+ // const itemsToNotify = new Set<ItemId>(transitioningItems);
191
+ // for (const trigger of interaction.triggers) {
192
+ // if (!('itemId' in trigger)) continue;
193
+ // itemsToNotify.add(trigger.itemId);
194
+ // }
195
+ // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
196
+ // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
197
+ // }
205
198
  }
206
199
  notifyItemTrigger(itemId, triggerType) {
207
- var _a, _b;
208
- const timestamp = Date.now();
209
- for (const interaction of this.interactions) {
210
- const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
211
- const matchingTrigger = interaction.triggers.find((trigger) => 'triggerEvent' in trigger
212
- && trigger.itemId === itemId
213
- && trigger.from === currentStateId
214
- && trigger.triggerEvent === triggerType);
215
- if (!matchingTrigger)
216
- continue;
217
- const activeStateId = this.getActiveInteractionState(interaction.id);
218
- const isNewStateActive = matchingTrigger.to === activeStateId;
219
- this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
220
- const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
221
- const state = interaction.states.find((state) => state.id === matchingTrigger.to);
222
- const actions = (_b = state === null || state === void 0 ? void 0 : state.actions) !== null && _b !== void 0 ? _b : [];
223
- for (const action of actions) {
224
- const ctrl = this.ctrls.get(action.itemId);
225
- if (!ctrl)
226
- continue;
227
- ctrl.receiveAction(action.type);
228
- }
229
- this.itemsStages = this.itemsStages.map((stage) => {
230
- if (stage.interactionId !== interaction.id)
231
- return stage;
232
- return {
233
- itemId: stage.itemId,
234
- interactionId: stage.interactionId,
235
- type: 'transitioning',
236
- from: stage.type === 'transitioning' ? stage.to : stage.stateId,
237
- to: matchingTrigger.to,
238
- direction: isNewStateActive ? 'in' : 'out',
239
- updated: timestamp
240
- };
241
- });
242
- const itemsToNotify = new Set(transitioningItems);
243
- for (const trigger of interaction.triggers) {
244
- if (!('itemId' in trigger))
245
- continue;
246
- itemsToNotify.add(trigger.itemId);
247
- }
248
- this.notifyItemCtrlsChange(Array.from(itemsToNotify));
249
- this.notifyTransitionStartForItems(transitioningItems, activeStateId);
250
- }
200
+ // const timestamp = Date.now();
201
+ // for (const interaction of this.interactions) {
202
+ // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
203
+ // const matchingTrigger = interaction.triggers.find((trigger) =>
204
+ // 'triggerEvent' in trigger
205
+ // && trigger.itemId === itemId
206
+ // && trigger.from === currentStateId
207
+ // && trigger.triggerEvent === triggerType
208
+ // );
209
+ // if (!matchingTrigger) continue;
210
+ // const activeStateId = this.getActiveInteractionState(interaction.id);
211
+ // const isNewStateActive = matchingTrigger.to === activeStateId;
212
+ // this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
213
+ // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
214
+ // const state = interaction.states.find((state) => state.id === matchingTrigger.to);
215
+ // const actions = state?.actions ?? [];
216
+ // for (const action of actions) {
217
+ // const ctrl = this.ctrls.get(action.itemId);
218
+ // if (!ctrl) continue;
219
+ // ctrl.receiveAction(action.type);
220
+ // }
221
+ // this.itemsStages = this.itemsStages.map((stage) => {
222
+ // if (stage.interactionId !== interaction.id) return stage;
223
+ // return {
224
+ // itemId: stage.itemId,
225
+ // interactionId: stage.interactionId,
226
+ // type: 'transitioning',
227
+ // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
228
+ // to: matchingTrigger.to,
229
+ // direction: isNewStateActive ? 'in' : 'out',
230
+ // updated: timestamp
231
+ // };
232
+ // });
233
+ // const itemsToNotify = new Set<ItemId>(transitioningItems);
234
+ // for (const trigger of interaction.triggers) {
235
+ // if (!('itemId' in trigger)) continue;
236
+ // itemsToNotify.add(trigger.itemId);
237
+ // }
238
+ // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
239
+ // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
240
+ // }
251
241
  }
252
242
  notifyTransitionStartForItems(itemsIds, activeStateId) {
253
243
  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-1",
3
+ "version": "1.9.13-3",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -156,97 +156,97 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
156
156
  }
157
157
 
158
158
  notifyScroll(position: number) {
159
- const timestamp = Date.now();
160
- for (const interaction of this.interactions) {
161
- const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
162
- const activeStateId = interaction.states.find((state) => state.id !== interaction.startStateId)?.id;
163
- const matchingTrigger = interaction.triggers.find((trigger) => {
164
- if (!('position' in trigger) || trigger.position === 0) return false;
165
- const triggerPosition = trigger.position * window.innerWidth;
166
- const isScrolledPastTrigger = triggerPosition < position;
167
- if (!isScrolledPastTrigger && !trigger.isReverse) return false;
168
- const stateId = isScrolledPastTrigger ? trigger.from : trigger.to;
169
- return stateId === currentStateId;
170
- });
171
- if (!matchingTrigger || !('position' in matchingTrigger) || !activeStateId) continue;
172
- const triggerPosition = matchingTrigger.position * window.innerWidth;
173
- const isScrolledPastTrigger = triggerPosition < position;
174
- const targetStateId = isScrolledPastTrigger ? matchingTrigger.to : matchingTrigger.from;
175
- this.setCurrentStateForInteraction(interaction.id, targetStateId);
176
- const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
177
- const state = interaction.states.find((state) => state.id === targetStateId);
178
- const actions = state?.actions ?? [];
179
- for (const action of actions) {
180
- const ctrl = this.ctrls.get(action.itemId);
181
- if (!ctrl) continue;
182
- ctrl.receiveAction(action.type);
183
- }
184
- const itemsStages = this.itemsStages.map((stage) => {
185
- if (stage.interactionId !== interaction.id) return stage;
186
- const newStage = {
187
- itemId: stage.itemId,
188
- interactionId: stage.interactionId,
189
- type: 'transitioning' as const,
190
- from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
191
- to: targetStateId,
192
- direction: targetStateId === activeStateId ? 'in' as const : 'out' as const,
193
- updated: timestamp
194
- };
195
- return newStage;
196
- });
197
- this.itemsStages = itemsStages;
198
- const itemsToNotify = new Set<ItemId>(transitioningItems);
199
- for (const trigger of interaction.triggers) {
200
- if (!('itemId' in trigger)) continue;
201
- itemsToNotify.add(trigger.itemId);
202
- }
203
- this.notifyItemCtrlsChange(Array.from(itemsToNotify));
204
- this.notifyTransitionStartForItems(transitioningItems, activeStateId);
205
- }
159
+ // const timestamp = Date.now();
160
+ // for (const interaction of this.interactions) {
161
+ // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
162
+ // const activeStateId = interaction.states.find((state) => state.id !== interaction.startStateId)?.id;
163
+ // const matchingTrigger = interaction.triggers.find((trigger) => {
164
+ // if (!('position' in trigger) || trigger.position === 0) return false;
165
+ // const triggerPosition = trigger.position * window.innerWidth;
166
+ // const isScrolledPastTrigger = triggerPosition < position;
167
+ // if (!isScrolledPastTrigger && !trigger.isReverse) return false;
168
+ // const stateId = isScrolledPastTrigger ? trigger.from : trigger.to;
169
+ // return stateId === currentStateId;
170
+ // });
171
+ // if (!matchingTrigger || !('position' in matchingTrigger) || !activeStateId) continue;
172
+ // const triggerPosition = matchingTrigger.position * window.innerWidth;
173
+ // const isScrolledPastTrigger = triggerPosition < position;
174
+ // const targetStateId = isScrolledPastTrigger ? matchingTrigger.to : matchingTrigger.from;
175
+ // this.setCurrentStateForInteraction(interaction.id, targetStateId);
176
+ // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
177
+ // const state = interaction.states.find((state) => state.id === targetStateId);
178
+ // const actions = state?.actions ?? [];
179
+ // for (const action of actions) {
180
+ // const ctrl = this.ctrls.get(action.itemId);
181
+ // if (!ctrl) continue;
182
+ // ctrl.receiveAction(action.type);
183
+ // }
184
+ // const itemsStages = this.itemsStages.map((stage) => {
185
+ // if (stage.interactionId !== interaction.id) return stage;
186
+ // const newStage = {
187
+ // itemId: stage.itemId,
188
+ // interactionId: stage.interactionId,
189
+ // type: 'transitioning' as const,
190
+ // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
191
+ // to: targetStateId,
192
+ // direction: targetStateId === activeStateId ? 'in' as const : 'out' as const,
193
+ // updated: timestamp
194
+ // };
195
+ // return newStage;
196
+ // });
197
+ // this.itemsStages = itemsStages;
198
+ // const itemsToNotify = new Set<ItemId>(transitioningItems);
199
+ // for (const trigger of interaction.triggers) {
200
+ // if (!('itemId' in trigger)) continue;
201
+ // itemsToNotify.add(trigger.itemId);
202
+ // }
203
+ // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
204
+ // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
205
+ // }
206
206
  }
207
207
 
208
208
  notifyItemTrigger(itemId: string, triggerType: TriggerType): void {
209
- const timestamp = Date.now();
210
- for (const interaction of this.interactions) {
211
- const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
212
- const matchingTrigger = interaction.triggers.find((trigger) =>
213
- 'triggerEvent' in trigger
214
- && trigger.itemId === itemId
215
- && trigger.from === currentStateId
216
- && trigger.triggerEvent === triggerType
217
- );
218
- if (!matchingTrigger) continue;
219
- const activeStateId = this.getActiveInteractionState(interaction.id);
220
- const isNewStateActive = matchingTrigger.to === activeStateId;
221
- this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
222
- const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
223
- const state = interaction.states.find((state) => state.id === matchingTrigger.to);
224
- const actions = state?.actions ?? [];
225
- for (const action of actions) {
226
- const ctrl = this.ctrls.get(action.itemId);
227
- if (!ctrl) continue;
228
- ctrl.receiveAction(action.type);
229
- }
230
- this.itemsStages = this.itemsStages.map((stage) => {
231
- if (stage.interactionId !== interaction.id) return stage;
232
- return {
233
- itemId: stage.itemId,
234
- interactionId: stage.interactionId,
235
- type: 'transitioning',
236
- from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
237
- to: matchingTrigger.to,
238
- direction: isNewStateActive ? 'in' : 'out',
239
- updated: timestamp
240
- };
241
- });
242
- const itemsToNotify = new Set<ItemId>(transitioningItems);
243
- for (const trigger of interaction.triggers) {
244
- if (!('itemId' in trigger)) continue;
245
- itemsToNotify.add(trigger.itemId);
246
- }
247
- this.notifyItemCtrlsChange(Array.from(itemsToNotify));
248
- this.notifyTransitionStartForItems(transitioningItems, activeStateId);
249
- }
209
+ // const timestamp = Date.now();
210
+ // for (const interaction of this.interactions) {
211
+ // const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
212
+ // const matchingTrigger = interaction.triggers.find((trigger) =>
213
+ // 'triggerEvent' in trigger
214
+ // && trigger.itemId === itemId
215
+ // && trigger.from === currentStateId
216
+ // && trigger.triggerEvent === triggerType
217
+ // );
218
+ // if (!matchingTrigger) continue;
219
+ // const activeStateId = this.getActiveInteractionState(interaction.id);
220
+ // const isNewStateActive = matchingTrigger.to === activeStateId;
221
+ // this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
222
+ // const transitioningItems = this.stateItemsIdsMap[activeStateId] ?? [];
223
+ // const state = interaction.states.find((state) => state.id === matchingTrigger.to);
224
+ // const actions = state?.actions ?? [];
225
+ // for (const action of actions) {
226
+ // const ctrl = this.ctrls.get(action.itemId);
227
+ // if (!ctrl) continue;
228
+ // ctrl.receiveAction(action.type);
229
+ // }
230
+ // this.itemsStages = this.itemsStages.map((stage) => {
231
+ // if (stage.interactionId !== interaction.id) return stage;
232
+ // return {
233
+ // itemId: stage.itemId,
234
+ // interactionId: stage.interactionId,
235
+ // type: 'transitioning',
236
+ // from: stage.type === 'transitioning' ? stage.to : stage.stateId!,
237
+ // to: matchingTrigger.to,
238
+ // direction: isNewStateActive ? 'in' : 'out',
239
+ // updated: timestamp
240
+ // };
241
+ // });
242
+ // const itemsToNotify = new Set<ItemId>(transitioningItems);
243
+ // for (const trigger of interaction.triggers) {
244
+ // if (!('itemId' in trigger)) continue;
245
+ // itemsToNotify.add(trigger.itemId);
246
+ // }
247
+ // this.notifyItemCtrlsChange(Array.from(itemsToNotify));
248
+ // this.notifyTransitionStartForItems(transitioningItems, activeStateId);
249
+ // }
250
250
  }
251
251
 
252
252
  notifyTransitionStartForItems(itemsIds: string[], activeStateId: string) {