inviton-powerduck 0.0.178 → 0.0.180

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.
@@ -136,6 +136,100 @@ export class ModalUtils {
136
136
  }
137
137
  }
138
138
 
139
+ static bindModalBottomSheetHandle(getModal: () => HTMLElement, hideModal: () => void) {
140
+ if ((getModal() as any)?._dragBound) {
141
+ return;
142
+ }
143
+
144
+ setTimeout(() => {
145
+ const modal = getModal() as HTMLElement;
146
+ const modalDialog = modal.querySelector('.modal-dialog') as HTMLElement;
147
+ const dragHandle = modal.querySelector('.drag-handle');
148
+
149
+ let startY = 0;
150
+ let currentY = 0;
151
+ let isDragging = false;
152
+ const threshold = 100;
153
+ const cancelDragging = () => {
154
+ isDragging = false;
155
+ modal.classList.remove('modal-is-dragging');
156
+ };
157
+
158
+ const startDragging = () => {
159
+ isDragging = true;
160
+ modal.classList.add('modal-is-dragging');
161
+ };
162
+
163
+ const onMove = (y) => {
164
+ const translateY = Math.max(y - startY, 0);
165
+ modalDialog.style.transform = `translateY(${translateY}px)`;
166
+ };
167
+
168
+ const endDrag = () => {
169
+ cancelDragging();
170
+ const dragDistance = currentY - startY;
171
+
172
+ if (dragDistance > threshold) {
173
+ hideModal();
174
+ } else {
175
+ modalDialog.style.transform = 'translateY(0)';
176
+ }
177
+ };
178
+
179
+ // Touch events
180
+ dragHandle.addEventListener('touchstart', (e) => {
181
+ startY = (e as TouchEvent).touches[0].clientY;
182
+ startDragging();
183
+ });
184
+
185
+ dragHandle.addEventListener('touchmove', (e) => {
186
+ if (!isDragging) {
187
+ return;
188
+ }
189
+
190
+ currentY = (e as TouchEvent).touches[0].clientY;
191
+ onMove(currentY);
192
+ });
193
+
194
+ dragHandle.addEventListener('touchend', endDrag);
195
+
196
+ // Mouse events
197
+ dragHandle.addEventListener('mousedown', (e) => {
198
+ startY = (e as MouseEvent).clientY;
199
+ startDragging();
200
+
201
+ const onMouseMove = (e) => {
202
+ if (!isDragging) {
203
+ return;
204
+ }
205
+
206
+ currentY = e.clientY;
207
+ onMove(currentY);
208
+ e.preventDefault();
209
+ e.stopPropagation();
210
+ e.stopImmediatePropagation();
211
+ };
212
+
213
+ const onMouseUp = () => {
214
+ endDrag();
215
+ globalState.removeEventListener('mousemove', onMouseMove);
216
+ globalState.removeEventListener('mouseup', onMouseUp);
217
+ };
218
+
219
+ globalState.addEventListener('mousemove', onMouseMove);
220
+ globalState.addEventListener('mouseup', onMouseUp);
221
+ });
222
+
223
+ // Reset on modal hide
224
+ modal.addEventListener('hidden.bs.modal', () => {
225
+ cancelDragging();
226
+ modalDialog.style.transform = '';
227
+ });
228
+
229
+ (modal as any)._dragBound = true;
230
+ }, 100);
231
+ }
232
+
139
233
  private static _getModalJquery(modalElem: Element | IVue): JQuery {
140
234
  return globalState.jQuery(modalElem as any);
141
235
  }
@@ -122,98 +122,10 @@ class ModalComponent extends TsxComponent<ModalArgs> implements ModalArgs {
122
122
  return;
123
123
  }
124
124
 
125
- const modal = this.$refs.modalRoot as HTMLElement;
126
- if ((modal as any)?._dragBound) {
127
- return;
128
- }
129
-
130
- setTimeout(() => {
131
- const modal = this.$refs.modalRoot as HTMLElement;
132
- const modalDialog = modal.querySelector('.modal-dialog') as HTMLElement;
133
- const dragHandle = modal.querySelector('.drag-handle');
134
-
135
- let startY = 0;
136
- let currentY = 0;
137
- let isDragging = false;
138
- const threshold = 100;
139
- const cancelDragging = () => {
140
- isDragging = false;
141
- modal.classList.remove('modal-is-dragging');
142
- };
143
-
144
- const startDragging = () => {
145
- isDragging = true;
146
- modal.classList.add('modal-is-dragging');
147
- };
148
-
149
- const onMove = (y) => {
150
- const translateY = Math.max(y - startY, 0);
151
- modalDialog.style.transform = `translateY(${translateY}px)`;
152
- };
153
-
154
- const endDrag = () => {
155
- cancelDragging();
156
- const dragDistance = currentY - startY;
157
-
158
- if (dragDistance > threshold) {
159
- this.hide();
160
- } else {
161
- modalDialog.style.transform = 'translateY(0)';
162
- }
163
- };
164
-
165
- // Touch events
166
- dragHandle.addEventListener('touchstart', (e) => {
167
- startY = (e as TouchEvent).touches[0].clientY;
168
- startDragging();
169
- });
170
-
171
- dragHandle.addEventListener('touchmove', (e) => {
172
- if (!isDragging) {
173
- return;
174
- }
175
-
176
- currentY = (e as TouchEvent).touches[0].clientY;
177
- onMove(currentY);
178
- });
179
-
180
- dragHandle.addEventListener('touchend', endDrag);
181
-
182
- // Mouse events
183
- dragHandle.addEventListener('mousedown', (e) => {
184
- startY = (e as MouseEvent).clientY;
185
- startDragging();
186
-
187
- const onMouseMove = (e) => {
188
- if (!isDragging) {
189
- return;
190
- }
191
-
192
- currentY = e.clientY;
193
- onMove(currentY);
194
- e.preventDefault();
195
- e.stopPropagation();
196
- e.stopImmediatePropagation();
197
- };
198
-
199
- const onMouseUp = () => {
200
- endDrag();
201
- globalState.removeEventListener('mousemove', onMouseMove);
202
- globalState.removeEventListener('mouseup', onMouseUp);
203
- };
204
-
205
- globalState.addEventListener('mousemove', onMouseMove);
206
- globalState.addEventListener('mouseup', onMouseUp);
207
- });
208
-
209
- // Reset on modal hide
210
- modal.addEventListener('hidden.bs.modal', () => {
211
- cancelDragging();
212
- modalDialog.style.transform = '';
213
- });
214
-
215
- (modal as any)._dragBound = true;
216
- }, 100);
125
+ ModalUtils.bindModalBottomSheetHandle(
126
+ () => this.$refs.modalRoot as HTMLElement,
127
+ () => this.hide()
128
+ )
217
129
  }
218
130
 
219
131
  treatMobileAsBottomSheet(): boolean {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "inviton-powerduck",
3
3
  "type": "module",
4
- "version": "0.0.178",
4
+ "version": "0.0.180",
5
5
  "files": [
6
6
  "app/",
7
7
  "common/",