@gitlab/ui 137.2.3 → 137.2.5

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.
@@ -105,9 +105,11 @@ var script = {
105
105
  }
106
106
  },
107
107
  computed: {
108
+ hasContent() {
109
+ return Boolean(this.$scopedSlots.default);
110
+ },
108
111
  hasIconOnly() {
109
- // eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
110
- return Boolean(this.icon && Object.keys(this.$slots).length === 0);
112
+ return Boolean(this.icon) && !this.hasContent;
111
113
  },
112
114
  isCircularIcon() {
113
115
  return this.iconOpticallyAligned || ['issue-open-m', 'issue-close'].includes(this.icon);
@@ -142,7 +144,7 @@ var script = {
142
144
  },
143
145
  classes() {
144
146
  return ['gl-badge', 'badge', 'badge-pill', variantClass[this.variant], {
145
- '!gl-px-2': !this.$scopedSlots.default
147
+ '!gl-px-2': !this.hasContent
146
148
  }];
147
149
  }
148
150
  },
@@ -160,7 +162,7 @@ var script = {
160
162
  const __vue_script__ = script;
161
163
 
162
164
  /* template */
163
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c(_vm.computedTag,_vm._g(_vm._b({tag:"component",class:_vm.classes,attrs:{"role":_vm.role}},'component',_vm.computedProps,false),_vm.$listeners),[(_vm.icon)?_c('gl-icon',{staticClass:"gl-badge-icon",class:{ '-gl-ml-2': _vm.isCircularIcon },attrs:{"size":_vm.iconSizeComputed,"name":_vm.icon}}):_vm._e(),_vm._v(" "),(_vm.$slots.default)?_c('span',{staticClass:"gl-badge-content"},[_vm._t("default")],2):_vm._e()],1)};
165
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c(_vm.computedTag,_vm._g(_vm._b({tag:"component",class:_vm.classes,attrs:{"role":_vm.role}},'component',_vm.computedProps,false),_vm.$listeners),[(_vm.icon)?_c('gl-icon',{staticClass:"gl-badge-icon",class:{ '-gl-ml-2': _vm.isCircularIcon && _vm.hasContent },attrs:{"size":_vm.iconSizeComputed,"name":_vm.icon}}):_vm._e(),_vm._v(" "),(_vm.hasContent)?_c('span',{staticClass:"gl-badge-content"},[_vm._t("default")],2):_vm._e()],1)};
164
166
  var __vue_staticRenderFns__ = [];
165
167
 
166
168
  /* style */
@@ -338,14 +338,10 @@ var script = {
338
338
  },
339
339
  handleAutoClose(e) {
340
340
  var _this$$refs$baseDropd, _this$$refs$baseDropd2;
341
- if (this.autoClose && e.target.closest(ITEM_SELECTOR) && // The optional chaining here is to accommodate specs that use shallow mounting.
342
- // Ideally, those specs would either:
343
- // - stub out the `BaseDropdown` component to include a stub `containsElement` method, or
344
- // - use a full mount.
345
- //
346
- // Unfortunately, GitLab has many specs which do neither of these. So the simpler thing to do
347
- // is to optionally chain the method call here.
348
- (_this$$refs$baseDropd = (_this$$refs$baseDropd2 = this.$refs.baseDropdown).containsElement) !== null && _this$$refs$baseDropd !== void 0 && _this$$refs$baseDropd.call(_this$$refs$baseDropd2, e.target)) {
341
+ if (this.autoClose && e.target.closest(ITEM_SELECTOR) && // The ref is null when an item action destroys this component before the click bubbles here.
342
+ // The method is optionally chained to accommodate specs that shallow mount without stubbing
343
+ // `BaseDropdown`'s `containsElement`; GitLab has many such specs.
344
+ (_this$$refs$baseDropd = this.$refs.baseDropdown) !== null && _this$$refs$baseDropd !== void 0 && (_this$$refs$baseDropd2 = _this$$refs$baseDropd.containsElement) !== null && _this$$refs$baseDropd2 !== void 0 && _this$$refs$baseDropd2.call(_this$$refs$baseDropd, e.target)) {
349
345
  this.closeAndFocus();
350
346
  }
351
347
  },
@@ -15,11 +15,16 @@ const defaultEventType = click;
15
15
  */
16
16
  const activeEventTypes = new Set();
17
17
  let lastMousedown = null;
18
+ let isMouseDown = false;
18
19
  const globalListener = event => {
19
20
  callbacks.forEach((_ref, element) => {
20
21
  let callback = _ref.callback,
21
22
  eventTypes = _ref.eventTypes;
22
- const originalEvent = event.type === click ? lastMousedown || event : event;
23
+ // Safari doesn't focus <button> on click; focus moves to <body>, firing a focusin outside the
24
+ // dropdown before the button's own click handler runs. Fall back to the mousedown target only
25
+ // while the mouse is still down, so a later focusin (e.g. Tab) isn't judged by a stale target.
26
+ const usesMousedownFallback = event.type === click || event.type === focusin && isMouseDown;
27
+ const originalEvent = usesMousedownFallback ? lastMousedown || event : event;
23
28
  if (
24
29
  // Ignore events that aren't targeted outside the element
25
30
  element.contains(originalEvent.target) ||
@@ -44,16 +49,33 @@ const globalListener = event => {
44
49
  // We need to listen for mouse events because text selection fires click event only when selection ends.
45
50
  // This means that the click event target could differ from the element where it originally started.
46
51
  // As example: if we use mouse events we could guarantee that selecting text within a dropdown won't close it.
52
+ // This also covers the Safari focusin case described above, since that focusin is triggered by the
53
+ // same mousedown.
47
54
  const onMousedown = event => {
48
55
  lastMousedown = event;
56
+ isMouseDown = true;
49
57
  };
58
+
59
+ // Only clear the "is the mouse down" flag here. lastMousedown must survive until the click
60
+ // fires (click comes after mouseup), or releasing a text selection outside the element would
61
+ // wrongly close the dropdown.
62
+ const onMouseup = () => {
63
+ isMouseDown = false;
64
+ };
65
+ const mousedown = 'mousedown';
66
+ const mouseup = 'mouseup';
50
67
  const startListening = eventTypes => {
51
68
  eventTypes.forEach(eventType => {
52
69
  if (!activeEventTypes.has(eventType)) {
53
70
  // Listening to mousedown events, ensures that a text selection doesn't trigger the
54
- // GlOutsideDirective 'click' callback if the selection started within the target element.
55
- if (eventType === click) {
56
- document.addEventListener('mousedown', onMousedown);
71
+ // GlOutsideDirective 'click' callback if the selection started within the target element,
72
+ // and that a Safari focus-loss 'focusin' doesn't trigger the callback either. Tracked via
73
+ // activeEventTypes too, so it's only ever bound/unbound once, regardless of whether 'click'
74
+ // and 'focusin' are (de)activated together or separately.
75
+ if ((eventType === click || eventType === focusin) && !activeEventTypes.has(mousedown)) {
76
+ document.addEventListener(mousedown, onMousedown);
77
+ document.addEventListener(mouseup, onMouseup);
78
+ activeEventTypes.add(mousedown);
57
79
  }
58
80
 
59
81
  // Added { capture: true } to all event types to prevent the behavior discussed in https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/1686#note_412545027
@@ -66,6 +88,7 @@ const startListening = eventTypes => {
66
88
  }
67
89
  });
68
90
  lastMousedown = null;
91
+ isMouseDown = false;
69
92
  };
70
93
  const stopListening = eventTypesToUnbind => {
71
94
  eventTypesToUnbind.forEach(eventType => {
@@ -79,8 +102,12 @@ const stopListening = eventTypesToUnbind => {
79
102
  }
80
103
  }
81
104
  });
82
- if (eventTypesToUnbind.includes(click) && !activeEventTypes.has(click)) {
83
- document.removeEventListener('mousedown', onMousedown);
105
+
106
+ // Only unbind mousedown once neither 'click' nor 'focusin' need it anymore.
107
+ if (activeEventTypes.has(mousedown) && !activeEventTypes.has(click) && !activeEventTypes.has(focusin)) {
108
+ document.removeEventListener(mousedown, onMousedown);
109
+ document.removeEventListener(mouseup, onMouseup);
110
+ activeEventTypes.delete(mousedown);
84
111
  }
85
112
  };
86
113
  function parseBinding(_ref3) {
@@ -1,4 +1,4 @@
1
- import { extend, isVue3 } from '../../vue';
1
+ import { extend, isVue3, getVue3Constructor } from '../../vue';
2
2
  import { NAME_TRANSPORTER, NAME_TRANSPORTER_TARGET } from '../../constants/components';
3
3
  import { IS_BROWSER } from '../../constants/env';
4
4
  import { HTMLElement } from '../../constants/safe-types';
@@ -193,7 +193,8 @@ const BVTransporter = /*#__PURE__*/extend({
193
193
  return $nodes[0];
194
194
  }
195
195
  }
196
- const Teleport = this.$.appContext.config.globalProperties.constructor.Teleport;
196
+ const _getVue3Constructor = getVue3Constructor(this),
197
+ Teleport = _getVue3Constructor.Teleport;
197
198
  return h(Teleport, {
198
199
  to: this.container
199
200
  }, this.normalizeSlot());
@@ -1,4 +1,4 @@
1
- import { isVue3 } from '../vue';
1
+ import { isVue3, getVue3Constructor } from '../vue';
2
2
 
3
3
  function _arrayLikeToArray(r, a) {
4
4
  (null == a || a > r.length) && (a = r.length);
@@ -119,9 +119,6 @@ const extractEventHandlers = config => {
119
119
  cleanConfig
120
120
  };
121
121
  };
122
- const getVue3Constructor = parent => {
123
- return parent.$.appContext.config.globalProperties.constructor;
124
- };
125
122
  const BUILTIN_DIRECTIVES = ['show', 'model', 'bind', 'cloak', 'else', 'else-if', 'for', 'html', 'if', 'memo', 'on', 'once', 'pre', 'slot', 'text'];
126
123
  const resolveComponentOptions = Component => {
127
124
  const opts = typeof Component === 'function' && Component.options ? {
@@ -41,6 +41,16 @@ if (isGlobalVue3) {
41
41
  };
42
42
  }
43
43
  const isVue3 = instance => Boolean(instance.$);
44
+
45
+ // Roots created with `new (Vue.extend(Comp))()` expose `Comp`, not `Vue`, as the
46
+ // constructor. Walk up to the base so its options are never merged into helpers.
47
+ const getVue3Constructor = instance => {
48
+ let Ctor = instance.$.appContext.config.globalProperties.constructor;
49
+ while (Ctor.super) {
50
+ Ctor = Ctor.super;
51
+ }
52
+ return Ctor;
53
+ };
44
54
  const extend = Vue.extend.bind(Vue);
45
55
  function mergeData() {
46
56
  var _result$attrs, _result$props;
@@ -52,4 +62,4 @@ function mergeData() {
52
62
  };
53
63
  }
54
64
 
55
- export { COMPONENT_UID_KEY, REF_FOR_KEY, extend, isGlobalVue3, isVue3, mergeData };
65
+ export { COMPONENT_UID_KEY, REF_FOR_KEY, extend, getVue3Constructor, isGlobalVue3, isVue3, mergeData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "137.2.3",
3
+ "version": "137.2.5",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -137,7 +137,7 @@
137
137
  "@yarnpkg/lockfile": "^1.1.0",
138
138
  "acorn": "^8.18.0",
139
139
  "acorn-walk": "^8.3.5",
140
- "autoprefixer": "10.6.0",
140
+ "autoprefixer": "10.6.1",
141
141
  "axe-playwright": "^2.2.2",
142
142
  "babel-loader": "^9.2.1",
143
143
  "cypress": "15.21.1",
@@ -110,9 +110,11 @@ export default {
110
110
  },
111
111
  },
112
112
  computed: {
113
+ hasContent() {
114
+ return Boolean(this.$scopedSlots.default);
115
+ },
113
116
  hasIconOnly() {
114
- // eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
115
- return Boolean(this.icon && Object.keys(this.$slots).length === 0);
117
+ return Boolean(this.icon) && !this.hasContent;
116
118
  },
117
119
  isCircularIcon() {
118
120
  return this.iconOpticallyAligned || ['issue-open-m', 'issue-close'].includes(this.icon);
@@ -141,7 +143,7 @@ export default {
141
143
  'badge',
142
144
  'badge-pill',
143
145
  variantClass[this.variant],
144
- { '!gl-px-2': !this.$scopedSlots.default },
146
+ { '!gl-px-2': !this.hasContent },
145
147
  ];
146
148
  },
147
149
  },
@@ -168,11 +170,10 @@ export default {
168
170
  v-if="icon"
169
171
  class="gl-badge-icon"
170
172
  :size="iconSizeComputed"
171
- :class="{ '-gl-ml-2': isCircularIcon }"
173
+ :class="{ '-gl-ml-2': isCircularIcon && hasContent }"
172
174
  :name="icon"
173
175
  />
174
- <!-- eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots -->
175
- <span v-if="$slots.default" class="gl-badge-content">
176
+ <span v-if="hasContent" class="gl-badge-content">
176
177
  <slot></slot>
177
178
  </span>
178
179
  </component>
@@ -370,14 +370,10 @@ export default {
370
370
  if (
371
371
  this.autoClose &&
372
372
  e.target.closest(ITEM_SELECTOR) &&
373
- // The optional chaining here is to accommodate specs that use shallow mounting.
374
- // Ideally, those specs would either:
375
- // - stub out the `BaseDropdown` component to include a stub `containsElement` method, or
376
- // - use a full mount.
377
- //
378
- // Unfortunately, GitLab has many specs which do neither of these. So the simpler thing to do
379
- // is to optionally chain the method call here.
380
- this.$refs.baseDropdown.containsElement?.(e.target)
373
+ // The ref is null when an item action destroys this component before the click bubbles here.
374
+ // The method is optionally chained to accommodate specs that shallow mount without stubbing
375
+ // `BaseDropdown`'s `containsElement`; GitLab has many such specs.
376
+ this.$refs.baseDropdown?.containsElement?.(e.target)
381
377
  ) {
382
378
  this.closeAndFocus();
383
379
  }
@@ -15,10 +15,15 @@ const defaultEventType = click;
15
15
  */
16
16
  const activeEventTypes = new Set();
17
17
  let lastMousedown = null;
18
+ let isMouseDown = false;
18
19
 
19
20
  const globalListener = (event) => {
20
21
  callbacks.forEach(({ callback, eventTypes }, element) => {
21
- const originalEvent = event.type === click ? lastMousedown || event : event;
22
+ // Safari doesn't focus <button> on click; focus moves to <body>, firing a focusin outside the
23
+ // dropdown before the button's own click handler runs. Fall back to the mousedown target only
24
+ // while the mouse is still down, so a later focusin (e.g. Tab) isn't judged by a stale target.
25
+ const usesMousedownFallback = event.type === click || (event.type === focusin && isMouseDown);
26
+ const originalEvent = usesMousedownFallback ? lastMousedown || event : event;
22
27
  if (
23
28
  // Ignore events that aren't targeted outside the element
24
29
  element.contains(originalEvent.target) ||
@@ -45,17 +50,35 @@ const globalListener = (event) => {
45
50
  // We need to listen for mouse events because text selection fires click event only when selection ends.
46
51
  // This means that the click event target could differ from the element where it originally started.
47
52
  // As example: if we use mouse events we could guarantee that selecting text within a dropdown won't close it.
53
+ // This also covers the Safari focusin case described above, since that focusin is triggered by the
54
+ // same mousedown.
48
55
  const onMousedown = (event) => {
49
56
  lastMousedown = event;
57
+ isMouseDown = true;
50
58
  };
51
59
 
60
+ // Only clear the "is the mouse down" flag here. lastMousedown must survive until the click
61
+ // fires (click comes after mouseup), or releasing a text selection outside the element would
62
+ // wrongly close the dropdown.
63
+ const onMouseup = () => {
64
+ isMouseDown = false;
65
+ };
66
+
67
+ const mousedown = 'mousedown';
68
+ const mouseup = 'mouseup';
69
+
52
70
  const startListening = (eventTypes) => {
53
71
  eventTypes.forEach((eventType) => {
54
72
  if (!activeEventTypes.has(eventType)) {
55
73
  // Listening to mousedown events, ensures that a text selection doesn't trigger the
56
- // GlOutsideDirective 'click' callback if the selection started within the target element.
57
- if (eventType === click) {
58
- document.addEventListener('mousedown', onMousedown);
74
+ // GlOutsideDirective 'click' callback if the selection started within the target element,
75
+ // and that a Safari focus-loss 'focusin' doesn't trigger the callback either. Tracked via
76
+ // activeEventTypes too, so it's only ever bound/unbound once, regardless of whether 'click'
77
+ // and 'focusin' are (de)activated together or separately.
78
+ if ((eventType === click || eventType === focusin) && !activeEventTypes.has(mousedown)) {
79
+ document.addEventListener(mousedown, onMousedown);
80
+ document.addEventListener(mouseup, onMouseup);
81
+ activeEventTypes.add(mousedown);
59
82
  }
60
83
 
61
84
  // Added { capture: true } to all event types to prevent the behavior discussed in https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/1686#note_412545027
@@ -67,6 +90,7 @@ const startListening = (eventTypes) => {
67
90
  });
68
91
 
69
92
  lastMousedown = null;
93
+ isMouseDown = false;
70
94
  };
71
95
 
72
96
  const stopListening = (eventTypesToUnbind) => {
@@ -79,8 +103,15 @@ const stopListening = (eventTypesToUnbind) => {
79
103
  }
80
104
  });
81
105
 
82
- if (eventTypesToUnbind.includes(click) && !activeEventTypes.has(click)) {
83
- document.removeEventListener('mousedown', onMousedown);
106
+ // Only unbind mousedown once neither 'click' nor 'focusin' need it anymore.
107
+ if (
108
+ activeEventTypes.has(mousedown) &&
109
+ !activeEventTypes.has(click) &&
110
+ !activeEventTypes.has(focusin)
111
+ ) {
112
+ document.removeEventListener(mousedown, onMousedown);
113
+ document.removeEventListener(mouseup, onMouseup);
114
+ activeEventTypes.delete(mousedown);
84
115
  }
85
116
  };
86
117
 
@@ -1,4 +1,4 @@
1
- import { isVue3, extend } from '../../vue'
1
+ import { isVue3, extend, getVue3Constructor } from '../../vue'
2
2
  import { NAME_TRANSPORTER, NAME_TRANSPORTER_TARGET } from '../../constants/components'
3
3
  import { IS_BROWSER } from '../../constants/env'
4
4
  import { HTMLElement } from '../../constants/safe-types'
@@ -199,7 +199,7 @@ export const BVTransporter = /*#__PURE__*/ extend({
199
199
  }
200
200
  }
201
201
 
202
- const { Teleport } = this.$.appContext.config.globalProperties.constructor
202
+ const { Teleport } = getVue3Constructor(this)
203
203
 
204
204
  return h(
205
205
  Teleport,
@@ -1,4 +1,4 @@
1
- import { isVue3 } from '../vue'
1
+ import { isVue3, getVue3Constructor } from '../vue'
2
2
 
3
3
  // Regex to detect event handler props: onSomething or onSomethingOnce
4
4
  const EVENT_HANDLER_RE = /^on([A-Z][a-zA-Z]*)$/
@@ -61,10 +61,6 @@ const extractEventHandlers = config => {
61
61
  return { handlers, cleanConfig }
62
62
  }
63
63
 
64
- const getVue3Constructor = parent => {
65
- return parent.$.appContext.config.globalProperties.constructor
66
- }
67
-
68
64
  const BUILTIN_DIRECTIVES = [
69
65
  'show',
70
66
  'model',
@@ -47,6 +47,16 @@ if (isGlobalVue3) {
47
47
 
48
48
  const isVue3 = instance => Boolean(instance.$)
49
49
 
50
+ // Roots created with `new (Vue.extend(Comp))()` expose `Comp`, not `Vue`, as the
51
+ // constructor. Walk up to the base so its options are never merged into helpers.
52
+ const getVue3Constructor = instance => {
53
+ let Ctor = instance.$.appContext.config.globalProperties.constructor
54
+ while (Ctor.super) {
55
+ Ctor = Ctor.super
56
+ }
57
+ return Ctor
58
+ }
59
+
50
60
  const extend = Vue.extend.bind(Vue)
51
61
 
52
62
  function mergeData(...data) {
@@ -54,4 +64,4 @@ function mergeData(...data) {
54
64
  return { ...result, ...(result.attrs ?? {}), ...(result.props ?? {}) }
55
65
  }
56
66
 
57
- export { COMPONENT_UID_KEY, mergeData, isGlobalVue3, isVue3, extend }
67
+ export { COMPONENT_UID_KEY, mergeData, isGlobalVue3, isVue3, getVue3Constructor, extend }