@cntrl-site/sdk-nextjs 1.9.13-8 → 1.9.13-9

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.
@@ -110,7 +110,7 @@ class InteractionsRegistry {
110
110
  const timestamp = Date.now();
111
111
  for (const interaction of this.interactions) {
112
112
  const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
113
- const matchingTrigger = interaction.triggers.find(trigger => 'position' in trigger && trigger.position === 0 && trigger.from === currentStateId);
113
+ const matchingTrigger = interaction.triggers.find(trigger => ('position' in trigger && trigger.position === 0 && trigger.from === currentStateId) || trigger.type === 'item-scroll-position');
114
114
  if (!matchingTrigger)
115
115
  continue;
116
116
  const activeStateId = this.getActiveInteractionState(interaction.id);
@@ -151,24 +151,42 @@ class InteractionsRegistry {
151
151
  notifyScroll(position) {
152
152
  var _a, _b, _c;
153
153
  const timestamp = Date.now();
154
- const item = this.items.find((item) => item.id === this.items[0].id);
155
- const testtop = item.area[this.layoutId].top;
156
154
  for (const interaction of this.interactions) {
157
155
  const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
158
156
  const activeStateId = (_a = interaction.states.find((state) => state.id !== interaction.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
159
157
  const matchingTrigger = interaction.triggers.find((trigger) => {
160
- if (!('position' in trigger) || testtop === 0)
158
+ if (trigger.type !== 'scroll-position' && trigger.type !== 'item-scroll-position')
159
+ return false;
160
+ let triggerPosition;
161
+ if (trigger.type === 'scroll-position') {
162
+ if (trigger.position === 0)
163
+ return false;
164
+ triggerPosition = trigger.position * window.innerWidth;
165
+ }
166
+ if (trigger.type === 'item-scroll-position') {
167
+ const item = this.items.find((item) => item.id === trigger.itemId);
168
+ triggerPosition = item.area[this.layoutId].top;
169
+ }
170
+ if (!triggerPosition)
161
171
  return false;
162
- const triggerPosition = testtop * window.innerWidth;
163
172
  const isScrolledPastTrigger = triggerPosition < position;
164
173
  if (!isScrolledPastTrigger && !trigger.isReverse)
165
174
  return false;
166
175
  const stateId = isScrolledPastTrigger ? trigger.from : trigger.to;
167
176
  return stateId === currentStateId;
168
177
  });
169
- if (!matchingTrigger || !('position' in matchingTrigger) || !activeStateId)
178
+ if (!matchingTrigger || (matchingTrigger.type !== 'scroll-position' && matchingTrigger.type !== 'item-scroll-position') || !activeStateId)
179
+ continue;
180
+ let triggerPosition;
181
+ if (matchingTrigger.type === 'scroll-position') {
182
+ triggerPosition = matchingTrigger.position * window.innerWidth;
183
+ }
184
+ if (matchingTrigger.type === 'item-scroll-position') {
185
+ const item = this.items.find((item) => item.id === matchingTrigger.itemId);
186
+ triggerPosition = item.area[this.layoutId].top;
187
+ }
188
+ if (!triggerPosition)
170
189
  continue;
171
- const triggerPosition = testtop * window.innerWidth;
172
190
  const isScrolledPastTrigger = triggerPosition < position;
173
191
  const targetStateId = isScrolledPastTrigger ? matchingTrigger.to : matchingTrigger.from;
174
192
  this.setCurrentStateForInteraction(interaction.id, targetStateId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.13-8",
3
+ "version": "1.9.13-9",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -119,7 +119,7 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
119
119
  for (const interaction of this.interactions) {
120
120
  const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
121
121
  const matchingTrigger = interaction.triggers.find(trigger =>
122
- 'position' in trigger && trigger.position === 0 && trigger.from === currentStateId
122
+ ('position' in trigger && trigger.position === 0 && trigger.from === currentStateId) || trigger.type === 'item-scroll-position'
123
123
  );
124
124
  if (!matchingTrigger) continue;
125
125
  const activeStateId = this.getActiveInteractionState(interaction.id);
@@ -159,21 +159,36 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
159
159
 
160
160
  notifyScroll(position: number) {
161
161
  const timestamp = Date.now();
162
- const item = this.items.find((item) => item.id === this.items[0].id)!;
163
- const testtop = item.area[this.layoutId].top;
164
162
  for (const interaction of this.interactions) {
165
163
  const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
166
164
  const activeStateId = interaction.states.find((state) => state.id !== interaction.startStateId)?.id;
167
165
  const matchingTrigger = interaction.triggers.find((trigger) => {
168
- if (!('position' in trigger) || testtop === 0) return false;
169
- const triggerPosition = testtop * window.innerWidth;
166
+ if (trigger.type !== 'scroll-position' && trigger.type !== 'item-scroll-position') return false;
167
+ let triggerPosition;
168
+ if (trigger.type === 'scroll-position') {
169
+ if (trigger.position === 0) return false;
170
+ triggerPosition = trigger.position * window.innerWidth;
171
+ }
172
+ if (trigger.type === 'item-scroll-position') {
173
+ const item = this.items.find((item) => item.id === trigger.itemId)!;
174
+ triggerPosition = item.area[this.layoutId].top;
175
+ }
176
+ if (!triggerPosition) return false;
170
177
  const isScrolledPastTrigger = triggerPosition < position;
171
178
  if (!isScrolledPastTrigger && !trigger.isReverse) return false;
172
179
  const stateId = isScrolledPastTrigger ? trigger.from : trigger.to;
173
180
  return stateId === currentStateId;
174
181
  });
175
- if (!matchingTrigger || !('position' in matchingTrigger) || !activeStateId) continue;
176
- const triggerPosition = testtop * window.innerWidth;
182
+ if (!matchingTrigger || (matchingTrigger.type !== 'scroll-position' && matchingTrigger.type !== 'item-scroll-position') || !activeStateId) continue;
183
+ let triggerPosition;
184
+ if (matchingTrigger.type === 'scroll-position') {
185
+ triggerPosition = matchingTrigger.position * window.innerWidth;
186
+ }
187
+ if (matchingTrigger.type === 'item-scroll-position') {
188
+ const item = this.items.find((item) => item.id === matchingTrigger.itemId)!;
189
+ triggerPosition = item.area[this.layoutId].top;
190
+ }
191
+ if (!triggerPosition) continue;
177
192
  const isScrolledPastTrigger = triggerPosition < position;
178
193
  const targetStateId = isScrolledPastTrigger ? matchingTrigger.to : matchingTrigger.from;
179
194
  this.setCurrentStateForInteraction(interaction.id, targetStateId);