js-kompo-utils 1.0.25 → 1.0.27

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.
@@ -129,6 +129,10 @@ export default {
129
129
  optionsKey() {
130
130
  this.$nextTick(() => {
131
131
  this.teleportOptions()
132
+ if (this._panelObserver && this.$refs.selectOptions) {
133
+ this._panelObserver.disconnect()
134
+ this._panelObserver.observe(this.$refs.selectOptions)
135
+ }
132
136
  if (this.isFocused) this.refresh()
133
137
  })
134
138
  },
@@ -209,6 +213,19 @@ export default {
209
213
  window.addEventListener('scroll', this._onScroll, true)
210
214
  window.addEventListener('resize', this._onResize, { passive: true })
211
215
 
216
+ if (window.visualViewport) {
217
+ this._onViewportScroll = () => {
218
+ if (this._rafId) return
219
+ this._rafId = requestAnimationFrame(() => {
220
+ this._rafId = null
221
+ this.trackPosition()
222
+ })
223
+ }
224
+ this._onViewportResize = () => this.refresh()
225
+ window.visualViewport.addEventListener('scroll', this._onViewportScroll)
226
+ window.visualViewport.addEventListener('resize', this._onViewportResize)
227
+ }
228
+
212
229
  const opts = this.$refs.selectOptions
213
230
  const anchor = this.anchorEl()
214
231
  if (typeof ResizeObserver !== 'undefined') {
@@ -227,10 +244,17 @@ export default {
227
244
  })
228
245
  if (anchor) this._anchorObserver.observe(anchor)
229
246
  }
230
- if (typeof IntersectionObserver !== 'undefined' && anchor) {
247
+ const inOverlay = !!(anchor && anchor.closest('.kompoModal, .kompoDrawer, .vl-sidebar-l'))
248
+ if (inOverlay && typeof IntersectionObserver !== 'undefined' && anchor) {
249
+ let intersectionInitialised = false
231
250
  this._anchorIntersection = new IntersectionObserver((entries) => {
232
251
  const entry = entries[entries.length - 1]
233
- if (entry && entry.intersectionRatio === 0) this.blur()
252
+ if (!entry) return
253
+ if (!intersectionInitialised) {
254
+ intersectionInitialised = true
255
+ return
256
+ }
257
+ if (entry.intersectionRatio === 0) this.blur()
234
258
  }, { threshold: 0 })
235
259
  this._anchorIntersection.observe(anchor)
236
260
  }
@@ -245,6 +269,16 @@ export default {
245
269
  }
246
270
  window.removeEventListener('scroll', this._onScroll, true)
247
271
  window.removeEventListener('resize', this._onResize)
272
+ if (window.visualViewport) {
273
+ if (this._onViewportScroll) {
274
+ window.visualViewport.removeEventListener('scroll', this._onViewportScroll)
275
+ this._onViewportScroll = null
276
+ }
277
+ if (this._onViewportResize) {
278
+ window.visualViewport.removeEventListener('resize', this._onViewportResize)
279
+ this._onViewportResize = null
280
+ }
281
+ }
248
282
  if (this._panelObserver) {
249
283
  this._panelObserver.disconnect()
250
284
  this._panelObserver = null
@@ -294,8 +328,11 @@ export default {
294
328
 
295
329
  this.$nextTick(() => {
296
330
  const optsHeight = opts.offsetHeight
297
- const spaceBelow = window.innerHeight - rect.bottom
298
- const spaceAbove = rect.top
331
+ const vv = window.visualViewport
332
+ const viewportHeight = vv ? vv.height : window.innerHeight
333
+ const viewportTop = vv ? vv.offsetTop : 0
334
+ const spaceBelow = (viewportTop + viewportHeight) - rect.bottom
335
+ const spaceAbove = rect.top - viewportTop
299
336
  const shouldFlip = this.forceUp || (spaceBelow < optsHeight && spaceAbove > spaceBelow)
300
337
  this.flipUp = shouldFlip
301
338
  if (shouldFlip) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-kompo-utils",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "",
5
5
  "main": "app.js",
6
6
  "scripts": {