@swan-io/shared-business 8.13.0 → 8.13.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/shared-business",
3
- "version": "8.13.0",
3
+ "version": "8.13.1",
4
4
  "engines": {
5
5
  "node": ">=20.9.0",
6
6
  "yarn": "^1.22.0"
@@ -112,11 +112,14 @@ export const ChoicePicker = ({ tile = true, items, getId = identity, large = fal
112
112
  return;
113
113
  }
114
114
  // auto scroll to selected value on mobile
115
- const scrollContainer = containerRef.current;
115
+ const container = containerRef.current;
116
+ if (container == null) {
117
+ return;
118
+ }
116
119
  const index = items.findIndex(item => value === item);
117
- if (index !== -1 && scrollContainer instanceof HTMLDivElement) {
118
- const width = scrollContainer.offsetWidth;
119
- scrollContainer.scrollTo({ x: index * width, animated: false });
120
+ if (index !== -1 && container.element != null) {
121
+ const width = container.element.offsetWidth;
122
+ container.scrollTo({ x: index * width, animated: false });
120
123
  }
121
124
  // if no value is selected, select first item
122
125
  if (value == null && items[0] != null) {
@@ -129,10 +132,13 @@ export const ChoicePicker = ({ tile = true, items, getId = identity, large = fal
129
132
  if (desktop) {
130
133
  return;
131
134
  }
132
- const scrollContainer = containerRef.current;
133
- if (scrollContainer instanceof HTMLDivElement) {
134
- const scrollLeft = scrollContainer.scrollLeft;
135
- const width = scrollContainer.offsetWidth;
135
+ const container = containerRef.current;
136
+ if (container == null) {
137
+ return;
138
+ }
139
+ if (container.element != null) {
140
+ const scrollLeft = container.element.scrollLeft;
141
+ const width = container.element.offsetWidth;
136
142
  const index = clampValue(0, items.length - 1)(Math.round(scrollLeft / width));
137
143
  const item = items[index];
138
144
  if (item != null) {
@@ -146,37 +152,43 @@ export const ChoicePicker = ({ tile = true, items, getId = identity, large = fal
146
152
  };
147
153
  const onPressPrevious = () => {
148
154
  var _a;
149
- const scrollContainer = containerRef.current;
150
- if (scrollContainer instanceof HTMLDivElement) {
151
- const scrollLeft = scrollContainer.scrollLeft;
152
- const width = scrollContainer.offsetWidth;
155
+ const container = containerRef.current;
156
+ if (container == null) {
157
+ return;
158
+ }
159
+ if (container.element != null) {
160
+ const scrollLeft = container.element.scrollLeft;
161
+ const width = container.element.offsetWidth;
153
162
  const index = Math.round(scrollLeft / width);
154
163
  const previousIndex = Math.max(0, index - 1);
155
164
  // remove scroll snap during scroll animation to avoid weird behavior on older browsers
156
- scrollContainer.style.scrollSnapType = "none";
165
+ container.element.style.scrollSnapType = "none";
157
166
  (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ x: previousIndex * width, animated: true });
158
- detectScrollAnimationEnd(scrollContainer).onResolve(() => {
167
+ detectScrollAnimationEnd(container.element).onResolve(() => {
159
168
  // set back scroll snap
160
169
  // @ts-expect-error
161
- scrollContainer.style.scrollSnapType = null;
170
+ container.element.style.scrollSnapType = null;
162
171
  });
163
172
  }
164
173
  };
165
174
  const onPressNext = () => {
166
175
  var _a;
167
- const scrollContainer = containerRef.current;
168
- if (scrollContainer instanceof HTMLDivElement) {
169
- const scrollLeft = scrollContainer.scrollLeft;
170
- const width = scrollContainer.offsetWidth;
176
+ const container = containerRef.current;
177
+ if (container == null) {
178
+ return;
179
+ }
180
+ if (container.element != null) {
181
+ const scrollLeft = container.element.scrollLeft;
182
+ const width = container.element.offsetWidth;
171
183
  const index = Math.round(scrollLeft / width);
172
184
  const nextIndex = Math.min(items.length - 1, index + 1);
173
185
  // remove scroll snap during scroll animation to avoid weird behavior on older browsers
174
- scrollContainer.style.scrollSnapType = "none";
186
+ container.element.style.scrollSnapType = "none";
175
187
  (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ x: nextIndex * width, animated: true });
176
- detectScrollAnimationEnd(scrollContainer).onResolve(() => {
188
+ detectScrollAnimationEnd(container.element).onResolve(() => {
177
189
  // set back scroll snap
178
190
  // @ts-expect-error
179
- scrollContainer.style.scrollSnapType = null;
191
+ container.element.style.scrollSnapType = null;
180
192
  });
181
193
  }
182
194
  };