js-kompo-utils 1.0.28 → 1.0.29

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.
@@ -34,11 +34,15 @@
34
34
  <option v-for="opt in nativeOptionsList" :key="opt.value" :value="opt.value">{{ nativeLabel(opt) }}</option>
35
35
  </select>
36
36
  </div>
37
- <div class="vlOptions vlOptionsTeleported"
37
+ <div class="vlOptions"
38
38
  :key="optionsKey"
39
39
  ref="selectOptions"
40
40
  :style="optionsStyle"
41
- :class="{ 'vlOptionsFlipUp': flipUp, 'vlOptionsVisible': isFocused }">
41
+ :class="{
42
+ 'vlOptionsTeleported': useFloatingOptions,
43
+ 'vlOptionsFlipUp': useFloatingOptions && flipUp,
44
+ 'vlOptionsVisible': useFloatingOptions && isFocused
45
+ }">
42
46
  <template v-if="filteredOptions.length">
43
47
  <div v-for="(option,key) in filteredOptions" :key="option.value" :ref="key"
44
48
  class="vlOption"
@@ -85,7 +89,14 @@ export default {
85
89
  forceDown() {
86
90
  return !!this.$_config('openDownward') || this.$_config('autoOptionsPlacement') === false
87
91
  },
92
+ useFloatingOptions() {
93
+ const explicitFloating = this.$_config('floatingOptions')
94
+ if (explicitFloating !== undefined && explicitFloating !== null) return !!explicitFloating
95
+
96
+ return !!this.$_config('teleportedOptions') || this.forceUp
97
+ },
88
98
  optionsStyle() {
99
+ if (!this.useFloatingOptions) return null
89
100
  return this.isFocused ? null : { display: 'none' }
90
101
  },
91
102
  useNativeMobile() {
@@ -116,6 +127,14 @@ export default {
116
127
  },
117
128
  watch: {
118
129
  isFocused(focused) {
130
+ if (!this.useFloatingOptions) {
131
+ if (!focused) {
132
+ this.flipUp = false
133
+ this.detachListeners()
134
+ this.resetPanelStyles()
135
+ }
136
+ return
137
+ }
119
138
  if (focused) {
120
139
  this.attachListeners()
121
140
  this.$nextTick(() => {
@@ -129,9 +148,10 @@ export default {
129
148
  }
130
149
  },
131
150
  filteredOptions() {
132
- if (this.isFocused) this.$nextTick(() => this.queuePositionUpdate())
151
+ if (this.useFloatingOptions && this.isFocused) this.$nextTick(() => this.queuePositionUpdate())
133
152
  },
134
153
  optionsKey() {
154
+ if (!this.useFloatingOptions) return
135
155
  this.$nextTick(() => {
136
156
  this.teleportOptions()
137
157
  if (this.isFocused) this.startPositioning()
@@ -139,7 +159,7 @@ export default {
139
159
  },
140
160
  },
141
161
  mounted() {
142
- this.teleportOptions()
162
+ if (this.useFloatingOptions) this.teleportOptions()
143
163
  if (typeof window !== 'undefined' && window.matchMedia) {
144
164
  this.isTouchDevice = window.matchMedia('(pointer: coarse)').matches
145
165
  }
@@ -183,23 +203,56 @@ export default {
183
203
  tmp.innerHTML = str
184
204
  return (tmp.textContent || tmp.innerText || '').trim()
185
205
  },
186
- teleportOptions() {
206
+ teleportOptions(anchor = this.anchorEl()) {
207
+ if (!this.useFloatingOptions) return
187
208
  const opts = this.$refs.selectOptions
188
- if (opts && opts.parentNode !== document.body) {
189
- document.body.appendChild(opts)
209
+ const context = this.floatingContext(anchor)
210
+ const root = context?.root
211
+ if (opts && root && opts.parentNode !== root) {
212
+ root.appendChild(opts)
190
213
  }
191
214
  },
192
215
  cleanupOptions() {
216
+ if (!this.useFloatingOptions) return
193
217
  const opts = this.$refs.selectOptions
194
- if (opts && opts.parentNode === document.body) {
195
- document.body.removeChild(opts)
218
+ if (opts && opts.parentNode && this.$el && !this.$el.contains(opts)) {
219
+ opts.parentNode.removeChild(opts)
196
220
  }
197
221
  },
198
222
  anchorEl() {
199
223
  return this.$refs.taggableInput?.$el || this.$refs.input?.parentElement
200
224
  },
201
225
  overlayAncestor(anchor = this.anchorEl()) {
202
- return anchor?.closest('.kompoModal, .kompoDrawer, .vl-sidebar-l') || null
226
+ return anchor?.closest('.kompoModal, .kompoDrawer, .vl-sidebar-l, .vl-sidebar-r') || null
227
+ },
228
+ floatingContext(anchor = this.anchorEl()) {
229
+ if (!anchor || typeof document === 'undefined') return null
230
+
231
+ const drawerOrSidebar = anchor.closest('.kompoDrawer, .vl-sidebar-l, .vl-sidebar-r')
232
+ if (drawerOrSidebar && typeof window !== 'undefined') {
233
+ const position = window.getComputedStyle(drawerOrSidebar).position
234
+ if (position && position !== 'static') {
235
+ return {
236
+ root: drawerOrSidebar,
237
+ strategy: 'absolute',
238
+ zIndex: 5001,
239
+ }
240
+ }
241
+ }
242
+
243
+ if (this.overlayAncestor(anchor)) {
244
+ return {
245
+ root: document.body,
246
+ strategy: 'fixed',
247
+ zIndex: 5001,
248
+ }
249
+ }
250
+
251
+ return {
252
+ root: document.body,
253
+ strategy: 'absolute',
254
+ zIndex: 1000,
255
+ }
203
256
  },
204
257
  attachListeners() {
205
258
  if (this._listenersAttached) return
@@ -233,7 +286,10 @@ export default {
233
286
  if (!opts || !anchor || !this.isFocused) return
234
287
 
235
288
  this.stopPositioning()
236
- this.applyBasePanelStyles(opts, anchor)
289
+ this.teleportOptions(anchor)
290
+ const context = this.floatingContext(anchor)
291
+ if (!context) return
292
+ this.applyBasePanelStyles(opts, anchor, context)
237
293
  opts.style.visibility = 'hidden'
238
294
  opts.style.transform = 'translate3d(0px, 0px, 0)'
239
295
 
@@ -258,15 +314,16 @@ export default {
258
314
  this._autoUpdateCleanup()
259
315
  this._autoUpdateCleanup = null
260
316
  },
261
- applyBasePanelStyles(opts, anchor) {
262
- const inOverlay = !!this.overlayAncestor(anchor)
263
- opts.style.position = 'fixed'
317
+ applyBasePanelStyles(opts, anchor, context = this.floatingContext(anchor)) {
318
+ if (!context) return
319
+
320
+ opts.style.position = context.strategy
264
321
  opts.style.top = '0px'
265
322
  opts.style.left = '0px'
266
323
  opts.style.bottom = 'auto'
267
324
  opts.style.width = Math.round(anchor.getBoundingClientRect().width) + 'px'
268
325
  opts.style.maxHeight = '240px'
269
- opts.style.zIndex = inOverlay ? '5001' : '1000'
326
+ opts.style.zIndex = String(context.zIndex)
270
327
  opts.style.willChange = 'transform'
271
328
  },
272
329
  resetPanelStyles() {
@@ -315,6 +372,17 @@ export default {
315
372
  const referenceEl = anchor
316
373
  const positionVersion = this._positionVersion || 0
317
374
  const { placement, auto } = this.placementConfig()
375
+ const context = this.floatingContext(referenceEl)
376
+ if (!context) return
377
+
378
+ if (floatingEl.parentNode !== context.root) {
379
+ this.$nextTick(() => {
380
+ if (this.isFocused) this.startPositioning()
381
+ })
382
+ return
383
+ }
384
+
385
+ this.applyBasePanelStyles(floatingEl, referenceEl, context)
318
386
 
319
387
  const middleware = [
320
388
  offset(-1),
@@ -332,7 +400,7 @@ export default {
332
400
  ]
333
401
 
334
402
  computePosition(referenceEl, floatingEl, {
335
- strategy: 'fixed',
403
+ strategy: context.strategy,
336
404
  placement,
337
405
  middleware,
338
406
  }).then(({ x, y, placement, middlewareData }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-kompo-utils",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "",
5
5
  "main": "app.js",
6
6
  "scripts": {