@itfin/components 1.2.55 → 1.2.56
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
|
@@ -105,16 +105,17 @@ class itfModal extends Vue {
|
|
|
105
105
|
if (typeof window === 'undefined') {
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
|
+
let context = document.body;
|
|
108
109
|
if (this.appendToContext && this.$el instanceof Node && this.$el.parentNode) {
|
|
109
|
-
|
|
110
|
+
context = this.$el.closest('.itf-append-context') || document.body;
|
|
110
111
|
this.$el.parentNode.removeChild(this.$el);
|
|
111
112
|
context.appendChild(this.$el); // should append only to body
|
|
112
113
|
} else if (this.appendToBody && this.$el instanceof Node && this.$el.parentNode) {
|
|
113
114
|
this.$el.parentNode.removeChild(this.$el);
|
|
114
|
-
|
|
115
|
+
context.appendChild(this.$el); // should append only to body
|
|
115
116
|
}
|
|
116
|
-
const { default: Modal } = await import('
|
|
117
|
-
this.modalEl = new Modal(this.$el, { backdrop: 'static' });
|
|
117
|
+
const { default: Modal } = await import('./modalSrc');
|
|
118
|
+
this.modalEl = new Modal(this.$el, { context, backdrop: 'static' });
|
|
118
119
|
this.onVisibleChanged(this.value);
|
|
119
120
|
this.bindEvents();
|
|
120
121
|
}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap (v5.2.3): modal.js
|
|
4
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
5
|
+
* --------------------------------------------------------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { defineJQueryPlugin, getElementFromSelector, isRTL, isVisible, reflow } from 'bootstrap/js/src/util/index'
|
|
9
|
+
import EventHandler from 'bootstrap/js/src/dom/event-handler'
|
|
10
|
+
import SelectorEngine from 'bootstrap/js/src/dom/selector-engine'
|
|
11
|
+
import ScrollBarHelper from 'bootstrap/js/src/util/scrollbar'
|
|
12
|
+
import BaseComponent from 'bootstrap/js/src/base-component'
|
|
13
|
+
import Backdrop from 'bootstrap/js/src/util/backdrop'
|
|
14
|
+
import FocusTrap from 'bootstrap/js/src/util/focustrap'
|
|
15
|
+
import { enableDismissTrigger } from 'bootstrap/js/src/util/component-functions'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constants
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const NAME = 'modal'
|
|
22
|
+
const DATA_KEY = 'bs.modal'
|
|
23
|
+
const EVENT_KEY = `.${DATA_KEY}`
|
|
24
|
+
const DATA_API_KEY = '.data-api'
|
|
25
|
+
const ESCAPE_KEY = 'Escape'
|
|
26
|
+
|
|
27
|
+
const EVENT_HIDE = `hide${EVENT_KEY}`
|
|
28
|
+
const EVENT_HIDE_PREVENTED = `hidePrevented${EVENT_KEY}`
|
|
29
|
+
const EVENT_HIDDEN = `hidden${EVENT_KEY}`
|
|
30
|
+
const EVENT_SHOW = `show${EVENT_KEY}`
|
|
31
|
+
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
|
32
|
+
const EVENT_RESIZE = `resize${EVENT_KEY}`
|
|
33
|
+
const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
|
|
34
|
+
const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY}`
|
|
35
|
+
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
|
|
36
|
+
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
|
37
|
+
|
|
38
|
+
const CLASS_NAME_OPEN = 'modal-open'
|
|
39
|
+
const CLASS_NAME_FADE = 'fade'
|
|
40
|
+
const CLASS_NAME_SHOW = 'show'
|
|
41
|
+
const CLASS_NAME_STATIC = 'modal-static'
|
|
42
|
+
|
|
43
|
+
const OPEN_SELECTOR = '.modal.show'
|
|
44
|
+
const SELECTOR_DIALOG = '.modal-dialog'
|
|
45
|
+
const SELECTOR_MODAL_BODY = '.modal-body'
|
|
46
|
+
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="modal"]'
|
|
47
|
+
|
|
48
|
+
const Default = {
|
|
49
|
+
backdrop: true,
|
|
50
|
+
focus: true,
|
|
51
|
+
keyboard: true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const DefaultType = {
|
|
55
|
+
backdrop: '(boolean|string)',
|
|
56
|
+
focus: 'boolean',
|
|
57
|
+
keyboard: 'boolean'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Class definition
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
class Modal extends BaseComponent {
|
|
65
|
+
constructor(element, config) {
|
|
66
|
+
super(element, config)
|
|
67
|
+
console.info(this._config)
|
|
68
|
+
this._dialog = SelectorEngine.findOne(SELECTOR_DIALOG, this._element)
|
|
69
|
+
this._backdrop = this._initializeBackDrop()
|
|
70
|
+
this._focustrap = this._initializeFocusTrap()
|
|
71
|
+
this._isShown = false
|
|
72
|
+
this._isTransitioning = false
|
|
73
|
+
this._scrollBar = new ScrollBarHelper()
|
|
74
|
+
|
|
75
|
+
this._addEventListeners()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Getters
|
|
79
|
+
static get Default() {
|
|
80
|
+
return Default
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static get DefaultType() {
|
|
84
|
+
return DefaultType
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static get NAME() {
|
|
88
|
+
return NAME
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Public
|
|
92
|
+
toggle(relatedTarget) {
|
|
93
|
+
return this._isShown ? this.hide() : this.show(relatedTarget)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
show(relatedTarget) {
|
|
97
|
+
if (this._isShown || this._isTransitioning) {
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, {
|
|
102
|
+
relatedTarget
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
if (showEvent.defaultPrevented) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this._isShown = true
|
|
110
|
+
this._isTransitioning = true
|
|
111
|
+
|
|
112
|
+
this._scrollBar.hide()
|
|
113
|
+
console.info(this._config.context);
|
|
114
|
+
this._config.context.classList.add(CLASS_NAME_OPEN)
|
|
115
|
+
|
|
116
|
+
this._adjustDialog()
|
|
117
|
+
|
|
118
|
+
this._backdrop.show(() => this._showElement(relatedTarget))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
hide() {
|
|
122
|
+
if (!this._isShown || this._isTransitioning) {
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE)
|
|
127
|
+
|
|
128
|
+
if (hideEvent.defaultPrevented) {
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this._isShown = false
|
|
133
|
+
this._isTransitioning = true
|
|
134
|
+
this._focustrap.deactivate()
|
|
135
|
+
|
|
136
|
+
this._element.classList.remove(CLASS_NAME_SHOW)
|
|
137
|
+
|
|
138
|
+
this._queueCallback(() => this._hideModal(), this._element, this._isAnimated())
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
dispose() {
|
|
142
|
+
for (const htmlElement of [window, this._dialog]) {
|
|
143
|
+
EventHandler.off(htmlElement, EVENT_KEY)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this._backdrop.dispose()
|
|
147
|
+
this._focustrap.deactivate()
|
|
148
|
+
super.dispose()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
handleUpdate() {
|
|
152
|
+
this._adjustDialog()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Private
|
|
156
|
+
_initializeBackDrop() {
|
|
157
|
+
return new Backdrop({
|
|
158
|
+
isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value,
|
|
159
|
+
isAnimated: this._isAnimated()
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
_initializeFocusTrap() {
|
|
164
|
+
return new FocusTrap({
|
|
165
|
+
trapElement: this._element
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_showElement(relatedTarget) {
|
|
170
|
+
// try to append dynamic modal
|
|
171
|
+
if (!this._config.context.contains(this._element)) {
|
|
172
|
+
this._config.context.append(this._element)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this._element.style.display = 'block'
|
|
176
|
+
this._element.removeAttribute('aria-hidden')
|
|
177
|
+
this._element.setAttribute('aria-modal', true)
|
|
178
|
+
this._element.setAttribute('role', 'dialog')
|
|
179
|
+
this._element.scrollTop = 0
|
|
180
|
+
|
|
181
|
+
const modalBody = SelectorEngine.findOne(SELECTOR_MODAL_BODY, this._dialog)
|
|
182
|
+
if (modalBody) {
|
|
183
|
+
modalBody.scrollTop = 0
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
reflow(this._element)
|
|
187
|
+
|
|
188
|
+
this._element.classList.add(CLASS_NAME_SHOW)
|
|
189
|
+
|
|
190
|
+
const transitionComplete = () => {
|
|
191
|
+
if (this._config.focus) {
|
|
192
|
+
this._focustrap.activate()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this._isTransitioning = false
|
|
196
|
+
EventHandler.trigger(this._element, EVENT_SHOWN, {
|
|
197
|
+
relatedTarget
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this._queueCallback(transitionComplete, this._dialog, this._isAnimated())
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
_addEventListeners() {
|
|
205
|
+
EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, event => {
|
|
206
|
+
if (event.key !== ESCAPE_KEY) {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (this._config.keyboard) {
|
|
211
|
+
event.preventDefault()
|
|
212
|
+
this.hide()
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this._triggerBackdropTransition()
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
EventHandler.on(window, EVENT_RESIZE, () => {
|
|
220
|
+
if (this._isShown && !this._isTransitioning) {
|
|
221
|
+
this._adjustDialog()
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
EventHandler.on(this._element, EVENT_MOUSEDOWN_DISMISS, event => {
|
|
226
|
+
// a bad trick to segregate clicks that may start inside dialog but end outside, and avoid listen to scrollbar clicks
|
|
227
|
+
EventHandler.one(this._element, EVENT_CLICK_DISMISS, event2 => {
|
|
228
|
+
if (this._element !== event.target || this._element !== event2.target) {
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (this._config.backdrop === 'static') {
|
|
233
|
+
this._triggerBackdropTransition()
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (this._config.backdrop) {
|
|
238
|
+
this.hide()
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
_hideModal() {
|
|
245
|
+
this._element.style.display = 'none'
|
|
246
|
+
this._element.setAttribute('aria-hidden', true)
|
|
247
|
+
this._element.removeAttribute('aria-modal')
|
|
248
|
+
this._element.removeAttribute('role')
|
|
249
|
+
this._isTransitioning = false
|
|
250
|
+
|
|
251
|
+
this._backdrop.hide(() => {
|
|
252
|
+
this._config.context.classList.remove(CLASS_NAME_OPEN)
|
|
253
|
+
this._resetAdjustments()
|
|
254
|
+
this._scrollBar.reset()
|
|
255
|
+
EventHandler.trigger(this._element, EVENT_HIDDEN)
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
_isAnimated() {
|
|
260
|
+
return this._element.classList.contains(CLASS_NAME_FADE)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_triggerBackdropTransition() {
|
|
264
|
+
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED)
|
|
265
|
+
if (hideEvent.defaultPrevented) {
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
|
|
270
|
+
const initialOverflowY = this._element.style.overflowY
|
|
271
|
+
// return if the following background transition hasn't yet completed
|
|
272
|
+
if (initialOverflowY === 'hidden' || this._element.classList.contains(CLASS_NAME_STATIC)) {
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (!isModalOverflowing) {
|
|
277
|
+
this._element.style.overflowY = 'hidden'
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this._element.classList.add(CLASS_NAME_STATIC)
|
|
281
|
+
this._queueCallback(() => {
|
|
282
|
+
this._element.classList.remove(CLASS_NAME_STATIC)
|
|
283
|
+
this._queueCallback(() => {
|
|
284
|
+
this._element.style.overflowY = initialOverflowY
|
|
285
|
+
}, this._dialog)
|
|
286
|
+
}, this._dialog)
|
|
287
|
+
|
|
288
|
+
this._element.focus()
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* The following methods are used to handle overflowing modals
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
_adjustDialog() {
|
|
296
|
+
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
|
|
297
|
+
const scrollbarWidth = this._scrollBar.getWidth()
|
|
298
|
+
const isBodyOverflowing = scrollbarWidth > 0
|
|
299
|
+
|
|
300
|
+
if (isBodyOverflowing && !isModalOverflowing) {
|
|
301
|
+
const property = isRTL() ? 'paddingLeft' : 'paddingRight'
|
|
302
|
+
this._element.style[property] = `${scrollbarWidth}px`
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (!isBodyOverflowing && isModalOverflowing) {
|
|
306
|
+
const property = isRTL() ? 'paddingRight' : 'paddingLeft'
|
|
307
|
+
this._element.style[property] = `${scrollbarWidth}px`
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
_resetAdjustments() {
|
|
312
|
+
this._element.style.paddingLeft = ''
|
|
313
|
+
this._element.style.paddingRight = ''
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Static
|
|
317
|
+
static jQueryInterface(config, relatedTarget) {
|
|
318
|
+
return this.each(function () {
|
|
319
|
+
const data = Modal.getOrCreateInstance(this, config)
|
|
320
|
+
|
|
321
|
+
if (typeof config !== 'string') {
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (typeof data[config] === 'undefined') {
|
|
326
|
+
throw new TypeError(`No method named "${config}"`)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
data[config](relatedTarget)
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Data API implementation
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
|
339
|
+
const target = getElementFromSelector(this)
|
|
340
|
+
|
|
341
|
+
if (['A', 'AREA'].includes(this.tagName)) {
|
|
342
|
+
event.preventDefault()
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
EventHandler.one(target, EVENT_SHOW, showEvent => {
|
|
346
|
+
if (showEvent.defaultPrevented) {
|
|
347
|
+
// only register focus restorer if modal will actually get shown
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
EventHandler.one(target, EVENT_HIDDEN, () => {
|
|
352
|
+
if (isVisible(this)) {
|
|
353
|
+
this.focus()
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
// avoid conflict when clicking modal toggler while another one is open
|
|
359
|
+
const alreadyOpen = SelectorEngine.findOne(OPEN_SELECTOR)
|
|
360
|
+
if (alreadyOpen) {
|
|
361
|
+
Modal.getInstance(alreadyOpen).hide()
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const data = Modal.getOrCreateInstance(target)
|
|
365
|
+
|
|
366
|
+
data.toggle(this)
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
enableDismissTrigger(Modal)
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* jQuery
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
defineJQueryPlugin(Modal)
|
|
376
|
+
|
|
377
|
+
export default Modal
|