@gitlab/ui 72.12.0 → 72.12.1
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/CHANGELOG.md +7 -0
- package/dist/charts.js +14 -0
- package/dist/components/base/accordion/accordion.js +73 -0
- package/dist/components/base/accordion/accordion_item.js +133 -0
- package/dist/components/base/alert/alert.js +222 -0
- package/dist/components/base/avatar/avatar.js +160 -0
- package/dist/components/base/avatar_labeled/avatar_labeled.js +107 -0
- package/dist/components/base/avatar_link/avatar_link.js +47 -0
- package/dist/components/base/avatars_inline/avatars_inline.js +119 -0
- package/dist/components/base/badge/badge.js +105 -0
- package/dist/components/base/banner/banner.js +139 -0
- package/dist/components/base/breadcrumb/breadcrumb.js +122 -0
- package/dist/components/base/breadcrumb/breadcrumb_item.js +73 -0
- package/dist/components/base/broadcast_message/broadcast_message.js +112 -0
- package/dist/components/base/broadcast_message/constants.js +5 -0
- package/dist/components/base/button/button.js +151 -0
- package/dist/components/base/button_group/button_group.js +47 -0
- package/dist/components/base/card/card.js +71 -0
- package/dist/components/base/carousel/carousel.js +48 -0
- package/dist/components/base/carousel/carousel_slide.js +47 -0
- package/dist/components/base/collapse/collapse.js +59 -0
- package/dist/components/base/datepicker/datepicker.js +386 -0
- package/dist/components/base/daterange_picker/daterange_picker.js +288 -0
- package/dist/components/base/drawer/drawer.js +127 -0
- package/dist/components/base/dropdown/dropdown.js +261 -0
- package/dist/components/base/dropdown/dropdown_divider.js +48 -0
- package/dist/components/base/dropdown/dropdown_form.js +48 -0
- package/dist/components/base/dropdown/dropdown_item.js +131 -0
- package/dist/components/base/dropdown/dropdown_section_header.js +48 -0
- package/dist/components/base/dropdown/dropdown_text.js +48 -0
- package/dist/components/base/filtered_search/common_story_options.js +14 -0
- package/dist/components/base/filtered_search/filtered_search.js +388 -0
- package/dist/components/base/filtered_search/filtered_search_suggestion.js +89 -0
- package/dist/components/base/filtered_search/filtered_search_suggestion_list.js +138 -0
- package/dist/components/base/filtered_search/filtered_search_term.js +203 -0
- package/dist/components/base/filtered_search/filtered_search_token.js +384 -0
- package/dist/components/base/filtered_search/filtered_search_token_segment.js +420 -0
- package/dist/components/base/filtered_search/filtered_search_utils.js +242 -0
- package/dist/components/base/form/form.js +49 -0
- package/dist/components/base/form/form_checkbox/form_checkbox.js +78 -0
- package/dist/components/base/form/form_checkbox/form_checkbox_group.js +60 -0
- package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +79 -0
- package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +138 -0
- package/dist/components/base/form/form_checkbox_tree/models/constants.js +12 -0
- package/dist/components/base/form/form_checkbox_tree/models/node.js +51 -0
- package/dist/components/base/form/form_checkbox_tree/models/tree.js +199 -0
- package/dist/components/base/form/form_combobox/constants.js +55 -0
- package/dist/components/base/form/form_combobox/form_combobox.js +230 -0
- package/dist/components/base/form/form_date/form_date.js +143 -0
- package/dist/components/base/form/form_fields/form_field_validator.js +93 -0
- package/dist/components/base/form/form_fields/form_fields.js +214 -0
- package/dist/components/base/form/form_fields/mappers.js +13 -0
- package/dist/components/base/form/form_fields/validators.js +48 -0
- package/dist/components/base/form/form_group/form_group.js +97 -0
- package/dist/components/base/form/form_input/form_input.js +121 -0
- package/dist/components/base/form/form_input_group/form_input_group.js +108 -0
- package/dist/components/base/form/form_input_group/form_input_group_mixin.js +41 -0
- package/dist/components/base/form/form_radio/form_radio.js +65 -0
- package/dist/components/base/form/form_radio_group/form_radio_group.js +78 -0
- package/dist/components/base/form/form_select/constants.js +12 -0
- package/dist/components/base/form/form_select/form_select.js +82 -0
- package/dist/components/base/form/form_text/form_text.js +38 -0
- package/dist/components/base/form/form_textarea/form_textarea.js +112 -0
- package/dist/components/base/form/input_group_text/input_group_text.js +48 -0
- package/dist/components/base/icon/icon.js +111 -0
- package/dist/components/base/infinite_scroll/infinite_scroll.js +197 -0
- package/dist/components/base/keyset_pagination/keyset_pagination.js +151 -0
- package/dist/components/base/label/label.js +163 -0
- package/dist/components/base/link/link.js +50 -0
- package/dist/components/base/loading_icon/loading_icon.js +111 -0
- package/dist/components/base/markdown/markdown.js +52 -0
- package/dist/components/base/modal/modal.js +204 -0
- package/dist/components/base/nav/nav.js +48 -0
- package/dist/components/base/nav/nav_item.js +48 -0
- package/dist/components/base/nav/nav_item_dropdown.js +62 -0
- package/dist/components/base/navbar/navbar.js +48 -0
- package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +453 -0
- package/dist/components/base/new_dropdowns/base_dropdown/constants.js +4 -0
- package/dist/components/base/new_dropdowns/constants.js +21 -0
- package/dist/components/base/new_dropdowns/disclosure/constants.js +8 -0
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown.js +370 -0
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_group.js +110 -0
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.js +143 -0
- package/dist/components/base/new_dropdowns/disclosure/mock_data.js +147 -0
- package/dist/components/base/new_dropdowns/disclosure/utils.js +39 -0
- package/dist/components/base/new_dropdowns/listbox/listbox.js +767 -0
- package/dist/components/base/new_dropdowns/listbox/listbox_group.js +58 -0
- package/dist/components/base/new_dropdowns/listbox/listbox_item.js +91 -0
- package/dist/components/base/new_dropdowns/listbox/listbox_search_input.js +93 -0
- package/dist/components/base/new_dropdowns/listbox/mock_data.js +118 -0
- package/dist/components/base/new_dropdowns/listbox/utils.js +34 -0
- package/dist/components/base/paginated_list/paginated_list.js +180 -0
- package/dist/components/base/pagination/pagination.js +399 -0
- package/dist/components/base/path/data.js +34 -0
- package/dist/components/base/path/path.js +189 -0
- package/dist/components/base/popover/popover.js +110 -0
- package/dist/components/base/progress_bar/progress_bar.js +48 -0
- package/dist/components/base/search_box_by_click/search_box_by_click.js +235 -0
- package/dist/components/base/search_box_by_type/search_box_by_type.js +167 -0
- package/dist/components/base/segmented_control/segmented_control.js +109 -0
- package/dist/components/base/skeleton_loader/skeleton_loader.js +224 -0
- package/dist/components/base/sorting/sorting.js +171 -0
- package/dist/components/base/sorting/sorting_item.js +109 -0
- package/dist/components/base/table/constants.js +5 -0
- package/dist/components/base/table/table.js +89 -0
- package/dist/components/base/table_lite/table_lite.js +72 -0
- package/dist/components/base/tabs/constants.js +3 -0
- package/dist/components/base/tabs/tab/tab.js +83 -0
- package/dist/components/base/tabs/tabs/scrollable_tabs.js +143 -0
- package/dist/components/base/tabs/tabs/tabs.js +224 -0
- package/dist/components/base/toast/toast.js +82 -0
- package/dist/components/base/toggle/toggle.js +180 -0
- package/dist/components/base/token/token.js +85 -0
- package/dist/components/base/token_selector/helpers.js +5 -0
- package/dist/components/base/token_selector/token_container.js +165 -0
- package/dist/components/base/token_selector/token_selector.js +403 -0
- package/dist/components/base/token_selector/token_selector_dropdown.js +199 -0
- package/dist/components/base/tooltip/tooltip.js +55 -0
- package/dist/components/charts/area/area.js +311 -0
- package/dist/components/charts/bar/bar.js +253 -0
- package/dist/components/charts/chart/chart.js +215 -0
- package/dist/components/charts/column/column.js +226 -0
- package/dist/components/charts/discrete_scatter/discrete_scatter.js +203 -0
- package/dist/components/charts/gauge/gauge.js +208 -0
- package/dist/components/charts/heatmap/heatmap.js +295 -0
- package/dist/components/charts/heatmap/index.js +2 -0
- package/dist/components/charts/legend/legend.js +228 -0
- package/dist/components/charts/line/line.js +308 -0
- package/dist/components/charts/series_label/series_label.js +100 -0
- package/dist/components/charts/single_stat/single_stat.js +152 -0
- package/dist/components/charts/sparkline/sparkline.js +261 -0
- package/dist/components/charts/stacked_column/stacked_column.js +335 -0
- package/dist/components/charts/tooltip/tooltip.js +251 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_conversation/duo_chat_conversation.js +83 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_loader/duo_chat_loader.js +100 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message/copy_code_element.js +35 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message/duo_chat_message.js +115 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.js +104 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.js +64 -0
- package/dist/components/experimental/duo/chat/constants.js +23 -0
- package/dist/components/experimental/duo/chat/duo_chat.js +359 -0
- package/dist/components/experimental/duo/chat/mock_data.js +83 -0
- package/dist/components/experimental/duo/user_feedback/user_feedback.js +94 -0
- package/dist/components/experimental/duo/user_feedback/user_feedback_modal.js +124 -0
- package/dist/components/experimental/experiment_badge/constants.js +4 -0
- package/dist/components/experimental/experiment_badge/experiment_badge.js +107 -0
- package/dist/components/mixins/button_mixin.js +11 -0
- package/dist/components/mixins/safe_link_mixin.js +30 -0
- package/dist/components/mixins/tooltip_mixin.js +21 -0
- package/dist/components/regions/dashboard_skeleton/dashboard_skeleton.js +53 -0
- package/dist/components/regions/empty_state/empty_state.js +154 -0
- package/dist/components/shared_components/charts/tooltip_default_format.js +53 -0
- package/dist/components/shared_components/clear_icon_button/clear_icon_button.js +64 -0
- package/dist/components/shared_components/close_button/close_button.js +54 -0
- package/dist/components/utilities/animated_number/animated_number.js +131 -0
- package/dist/components/utilities/friendly_wrap/friendly_wrap.js +75 -0
- package/dist/components/utilities/intersection_observer/intersection_observer.js +88 -0
- package/dist/components/utilities/intersperse/intersperse.js +86 -0
- package/dist/components/utilities/sprintf/sprintf.js +172 -0
- package/dist/components/utilities/truncate/constants.js +7 -0
- package/dist/components/utilities/truncate/truncate.js +111 -0
- package/dist/components/utilities/truncate_text/constants.js +7 -0
- package/dist/components/utilities/truncate_text/truncate_text.js +146 -0
- package/dist/config.js +86 -0
- package/dist/directives/collapse_toggle.js +1 -0
- package/dist/directives/hover_load/hover_load.js +45 -0
- package/dist/directives/modal.js +1 -0
- package/dist/directives/outside/get_event_like_time_stamp.js +33 -0
- package/dist/directives/outside/outside.js +106 -0
- package/dist/directives/resize_observer/resize_observer.js +51 -0
- package/dist/directives/safe_html/constants.js +6 -0
- package/dist/directives/safe_html/safe_html.js +39 -0
- package/dist/directives/safe_link/mock_data.js +10 -0
- package/dist/directives/safe_link/safe_link.js +65 -0
- package/dist/directives/tooltip.js +1 -0
- package/dist/index.css +7 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +105 -0
- package/dist/tokens/common_story_options.js +54 -0
- package/dist/tokens/css/tokens.css +1 -1
- package/dist/tokens/css/tokens.dark.css +1 -1
- package/dist/tokens/js/tokens.dark.js +1 -1
- package/dist/tokens/js/tokens.js +1 -1
- package/dist/tokens/scss/_tokens.dark.scss +1 -1
- package/dist/tokens/scss/_tokens.scss +1 -1
- package/dist/utils/breakpoints.js +20 -0
- package/dist/utils/charts/config.js +556 -0
- package/dist/utils/charts/constants.js +63 -0
- package/dist/utils/charts/mock_data.js +211 -0
- package/dist/utils/charts/story_config.js +42 -0
- package/dist/utils/charts/theme.js +192 -0
- package/dist/utils/charts/utils.js +54 -0
- package/dist/utils/constants.js +288 -0
- package/dist/utils/data_utils.js +21 -0
- package/dist/utils/datetime_utility.js +61 -0
- package/dist/utils/i18n.js +15 -0
- package/dist/utils/is_slot_empty.js +38 -0
- package/dist/utils/number_utils.js +124 -0
- package/dist/utils/stories_constants.js +29 -0
- package/dist/utils/stories_utils.js +13 -0
- package/dist/utils/story_decorators/container.js +16 -0
- package/dist/utils/string_utils.js +69 -0
- package/dist/utils/svgs/svg_paths.js +7 -0
- package/dist/utils/test_utils.js +33 -0
- package/dist/utils/use_fake_date.js +29 -0
- package/dist/utils/use_mock_intersection_observer.js +108 -0
- package/dist/utils/utils.js +197 -0
- package/dist/utils.js +5 -0
- package/package.json +1 -1
package/dist/config.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BVConfigPlugin } from 'bootstrap-vue/esm/index.js';
|
|
2
|
+
import Vue from 'vue';
|
|
3
|
+
import translationKeys from '../translations.json';
|
|
4
|
+
import { tooltipDelay } from './utils/constants';
|
|
5
|
+
|
|
6
|
+
const bFormTextGlobalConfig = {
|
|
7
|
+
textVariant: 'gl-muted'
|
|
8
|
+
};
|
|
9
|
+
const tooltipGlobalConfig = {
|
|
10
|
+
// Work around for https://github.com/bootstrap-vue/bootstrap-vue/issues/6507
|
|
11
|
+
boundaryPadding: 5,
|
|
12
|
+
customClass: 'gl-tooltip',
|
|
13
|
+
delay: tooltipDelay
|
|
14
|
+
};
|
|
15
|
+
const popoverDelayConfig = {
|
|
16
|
+
show: 50,
|
|
17
|
+
// BootstrapVue's default delay on show.
|
|
18
|
+
hide: 150 // Increased hide delay so that it doesn't disappear to quickly when user attempts to interact with the content.
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Guard against nonexistent localStorage,
|
|
23
|
+
* or corrupted localStorage
|
|
24
|
+
*
|
|
25
|
+
* localStorage access is not possible in certain environments like
|
|
26
|
+
* - in iframe usage in Chrome if embedded on another domain
|
|
27
|
+
* - tests / node
|
|
28
|
+
*/
|
|
29
|
+
try {
|
|
30
|
+
const glTooltipDelay = localStorage.getItem('gl-tooltip-delay');
|
|
31
|
+
if (glTooltipDelay) {
|
|
32
|
+
tooltipGlobalConfig.delay = JSON.parse(glTooltipDelay);
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
// localStorage doesn't exist (or the value is not properly formatted)
|
|
36
|
+
}
|
|
37
|
+
const i18n = translationKeys;
|
|
38
|
+
let configured = false;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Set GitLab UI configuration.
|
|
42
|
+
*
|
|
43
|
+
* @typedef {object} GitLabUIConfiguration
|
|
44
|
+
* @template TValue=string
|
|
45
|
+
* @property {undefined | Object} translations Generic translations for component labels to fall back to.
|
|
46
|
+
* @property {boolean} disableTranslations Whether translation capabilities should be disabled. Suppresses the warning about missing translations.
|
|
47
|
+
*/
|
|
48
|
+
const setConfigs = function () {
|
|
49
|
+
let {
|
|
50
|
+
translations
|
|
51
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
52
|
+
if (configured) {
|
|
53
|
+
if (process.env.NODE_ENV === 'development') {
|
|
54
|
+
throw new Error('GitLab UI can only be configured once!');
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
configured = true;
|
|
59
|
+
Vue.use(BVConfigPlugin, {
|
|
60
|
+
BFormText: bFormTextGlobalConfig,
|
|
61
|
+
BTooltip: tooltipGlobalConfig,
|
|
62
|
+
BPopover: {
|
|
63
|
+
delay: popoverDelayConfig
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (typeof translations === 'object') {
|
|
67
|
+
if (process.env.NODE_ENV === 'development') {
|
|
68
|
+
const undefinedTranslationKeys = Object.keys(i18n).reduce((acc, current) => {
|
|
69
|
+
if (!(current in translations)) {
|
|
70
|
+
acc.push(current);
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
}, []);
|
|
74
|
+
if (undefinedTranslationKeys.length) {
|
|
75
|
+
/* eslint-disable no-console */
|
|
76
|
+
console.warn('[@gitlab/ui] The following translations have not been given, so will fall back to their default US English strings:');
|
|
77
|
+
console.table(undefinedTranslationKeys);
|
|
78
|
+
/* eslint-enable no-console */
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
Object.assign(i18n, translations);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default setConfigs;
|
|
86
|
+
export { i18n };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VBToggle as GlCollapseToggleDirective } from 'bootstrap-vue/esm/index.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import isFunction from 'lodash/isFunction';
|
|
2
|
+
|
|
3
|
+
const DELAY_ON_HOVER = 100;
|
|
4
|
+
let mouseOverTimer;
|
|
5
|
+
let mouseOverHandler;
|
|
6
|
+
const bind = (el, _ref) => {
|
|
7
|
+
let {
|
|
8
|
+
value: loadHandler
|
|
9
|
+
} = _ref;
|
|
10
|
+
if (!isFunction(loadHandler)) {
|
|
11
|
+
throw TypeError('Directive value must be a function');
|
|
12
|
+
}
|
|
13
|
+
const mouseOutHandler = () => {
|
|
14
|
+
if (mouseOverTimer) {
|
|
15
|
+
clearTimeout(mouseOverTimer);
|
|
16
|
+
mouseOverTimer = undefined;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
mouseOverHandler = () => {
|
|
20
|
+
el.addEventListener('mouseout', mouseOutHandler, {
|
|
21
|
+
passive: true
|
|
22
|
+
});
|
|
23
|
+
mouseOverTimer = setTimeout(() => {
|
|
24
|
+
loadHandler(el);
|
|
25
|
+
|
|
26
|
+
// Only execute once
|
|
27
|
+
el.removeEventListener('mouseover', mouseOverHandler, true);
|
|
28
|
+
el.removeEventListener('mouseout', mouseOutHandler);
|
|
29
|
+
mouseOverTimer = undefined;
|
|
30
|
+
}, DELAY_ON_HOVER);
|
|
31
|
+
};
|
|
32
|
+
el.addEventListener('mouseover', mouseOverHandler, {
|
|
33
|
+
capture: true,
|
|
34
|
+
passive: true
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const unbind = el => {
|
|
38
|
+
el.removeEventListener('mouseover', mouseOverHandler, true);
|
|
39
|
+
};
|
|
40
|
+
const HoverLoadDirective = {
|
|
41
|
+
bind,
|
|
42
|
+
unbind
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { DELAY_ON_HOVER, HoverLoadDirective };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VBModal as GlModalDirective } from 'bootstrap-vue/esm/index.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is based on Vue's scheduler code:
|
|
3
|
+
* https://github.com/vuejs/vue/blob/v2.6.12/src/core/observer/scheduler.js#L44-L66
|
|
4
|
+
*
|
|
5
|
+
* See the LICENSE file in this directory.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
performance
|
|
10
|
+
} = window;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get a current timestamp that can be meaningfully compared to an event's
|
|
14
|
+
* `timeStamp` property.
|
|
15
|
+
*
|
|
16
|
+
* Event timestamps can be a DOMHighResTimeStamp (if supported), otherwise
|
|
17
|
+
* a DOMTimeStamp (used by jsdom and older browsers).
|
|
18
|
+
*
|
|
19
|
+
* This function will return a current timestamp of the same type used by the
|
|
20
|
+
* underlying environment when it creates DOM events.
|
|
21
|
+
*
|
|
22
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp for
|
|
23
|
+
* more details.
|
|
24
|
+
*
|
|
25
|
+
* @returns {number}
|
|
26
|
+
*/
|
|
27
|
+
const getEventLikeTimeStamp =
|
|
28
|
+
// If the event timestamp, although evaluated AFTER the Date.now(), is
|
|
29
|
+
// smaller, it means the event is using a hi-res timestamp, and we need to
|
|
30
|
+
// use the hi-res version for event listener timestamps as well.
|
|
31
|
+
typeof (performance === null || performance === void 0 ? void 0 : performance.now) === 'function' && Date.now() > document.createEvent('Event').timeStamp ? () => performance.now() : () => Date.now();
|
|
32
|
+
|
|
33
|
+
export { getEventLikeTimeStamp };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getEventLikeTimeStamp } from './get_event_like_time_stamp';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Map<HTMLElement, { bindTimeStamp: number, callback: Function }>
|
|
5
|
+
*/
|
|
6
|
+
const callbacks = new Map();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Is a global listener already set up?
|
|
10
|
+
*/
|
|
11
|
+
let listening = false;
|
|
12
|
+
let lastMousedown = null;
|
|
13
|
+
const globalListener = event => {
|
|
14
|
+
callbacks.forEach((_ref, element) => {
|
|
15
|
+
let {
|
|
16
|
+
bindTimeStamp,
|
|
17
|
+
callback
|
|
18
|
+
} = _ref;
|
|
19
|
+
const originalEvent = lastMousedown || event;
|
|
20
|
+
if (
|
|
21
|
+
// Ignore events that aren't targeted outside the element
|
|
22
|
+
element.contains(originalEvent.target) ||
|
|
23
|
+
// Only consider events triggered after the directive was bound
|
|
24
|
+
event.timeStamp <= bindTimeStamp) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
callback(event);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.error(e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
lastMousedown = null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// We need to listen for mouse events because text selection fires click event only when selection ends.
|
|
40
|
+
// This means that the click event target could differ from the element where it originally started.
|
|
41
|
+
// As example: if we use mouse events we could guarantee that selecting text within a dropdown won't close it.
|
|
42
|
+
const onMousedown = event => {
|
|
43
|
+
lastMousedown = event;
|
|
44
|
+
};
|
|
45
|
+
const startListening = () => {
|
|
46
|
+
if (listening) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
document.addEventListener('mousedown', onMousedown);
|
|
50
|
+
document.addEventListener('click', globalListener, {
|
|
51
|
+
capture: true
|
|
52
|
+
});
|
|
53
|
+
listening = true;
|
|
54
|
+
lastMousedown = null;
|
|
55
|
+
};
|
|
56
|
+
const stopListening = () => {
|
|
57
|
+
if (!listening) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
document.removeEventListener('mousedown', onMousedown);
|
|
61
|
+
document.removeEventListener('click', globalListener);
|
|
62
|
+
listening = false;
|
|
63
|
+
};
|
|
64
|
+
const bind = (el, _ref2) => {
|
|
65
|
+
let {
|
|
66
|
+
value,
|
|
67
|
+
arg = 'click'
|
|
68
|
+
} = _ref2;
|
|
69
|
+
if (typeof value !== 'function') {
|
|
70
|
+
throw new Error(`[GlOutsideDirective] Value must be a function; got ${typeof value}!`);
|
|
71
|
+
}
|
|
72
|
+
if (arg !== 'click') {
|
|
73
|
+
throw new Error(`[GlOutsideDirective] Cannot bind ${arg} events; only click events are currently supported!`);
|
|
74
|
+
}
|
|
75
|
+
if (callbacks.has(el)) {
|
|
76
|
+
// This element is already bound. This is possible if two components, which
|
|
77
|
+
// share the same root node, (i.e., one is a higher-order component
|
|
78
|
+
// wrapping another) _both_ have this directive applied.
|
|
79
|
+
//
|
|
80
|
+
// Because Vue binds directives in the direction towards the root, only the
|
|
81
|
+
// deepest instance of this directive will be bound.
|
|
82
|
+
//
|
|
83
|
+
// A future iteration may add support for binding all instances on a given
|
|
84
|
+
// element.
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!listening) {
|
|
88
|
+
startListening();
|
|
89
|
+
}
|
|
90
|
+
callbacks.set(el, {
|
|
91
|
+
bindTimeStamp: getEventLikeTimeStamp(),
|
|
92
|
+
callback: value
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const unbind = el => {
|
|
96
|
+
callbacks.delete(el);
|
|
97
|
+
if (callbacks.size === 0) {
|
|
98
|
+
stopListening();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const OutsideDirective = {
|
|
102
|
+
bind,
|
|
103
|
+
unbind
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export { OutsideDirective };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import isFunction from 'lodash/isFunction';
|
|
2
|
+
|
|
3
|
+
let observer = null;
|
|
4
|
+
const attachObserver = (el, resizeHandler) => {
|
|
5
|
+
if (!isFunction(resizeHandler)) {
|
|
6
|
+
throw TypeError('directive value must be a function');
|
|
7
|
+
}
|
|
8
|
+
if (!observer) {
|
|
9
|
+
// the observer instance is shared for performance reasons
|
|
10
|
+
// more information: https://github.com/WICG/ResizeObserver/issues/59
|
|
11
|
+
observer = new ResizeObserver(entries => {
|
|
12
|
+
entries.forEach(event => {
|
|
13
|
+
event.target.glResizeHandler(event);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
el.glResizeHandler = resizeHandler;
|
|
18
|
+
observer.observe(el);
|
|
19
|
+
};
|
|
20
|
+
const detachObserver = el => {
|
|
21
|
+
if (el.glResizeHandler) {
|
|
22
|
+
var _observer;
|
|
23
|
+
delete el.glResizeHandler;
|
|
24
|
+
(_observer = observer) === null || _observer === void 0 ? void 0 : _observer.unobserve(el);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const GlResizeObserverDirective = {
|
|
28
|
+
bind(el, _ref) {
|
|
29
|
+
let {
|
|
30
|
+
value: resizeHandler,
|
|
31
|
+
arg: enabled = true
|
|
32
|
+
} = _ref;
|
|
33
|
+
if (enabled) {
|
|
34
|
+
attachObserver(el, resizeHandler);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
update(el, _ref2) {
|
|
38
|
+
let {
|
|
39
|
+
value: resizeHandler,
|
|
40
|
+
arg: enabled = true
|
|
41
|
+
} = _ref2;
|
|
42
|
+
if (enabled) {
|
|
43
|
+
attachObserver(el, resizeHandler);
|
|
44
|
+
} else {
|
|
45
|
+
detachObserver(el);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
unbind: detachObserver
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { GlResizeObserverDirective };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// See https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1421#note_617098438
|
|
2
|
+
// for more details
|
|
3
|
+
const forbiddenDataAttrs = ['data-remote', 'data-url', 'data-type', 'data-method', 'data-disable-with', 'data-disabled', 'data-disable', 'data-turbo'];
|
|
4
|
+
const forbiddenTags = ['style', 'mstyle', 'form'];
|
|
5
|
+
|
|
6
|
+
export { forbiddenDataAttrs, forbiddenTags };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import DOMPurify from 'dompurify';
|
|
2
|
+
import { forbiddenDataAttrs, forbiddenTags } from './constants';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
sanitize
|
|
6
|
+
} = DOMPurify;
|
|
7
|
+
|
|
8
|
+
// Mitigate against future dompurify mXSS bypasses by
|
|
9
|
+
// avoiding additional serialize/parse round trip.
|
|
10
|
+
// See https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/1782
|
|
11
|
+
// and https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2127
|
|
12
|
+
// for more details.
|
|
13
|
+
const DEFAULT_CONFIG = {
|
|
14
|
+
RETURN_DOM_FRAGMENT: true,
|
|
15
|
+
ALLOW_UNKNOWN_PROTOCOLS: true,
|
|
16
|
+
FORBID_ATTR: forbiddenDataAttrs,
|
|
17
|
+
FORBID_TAGS: forbiddenTags
|
|
18
|
+
};
|
|
19
|
+
const transform = (el, binding) => {
|
|
20
|
+
if (binding.oldValue !== binding.value) {
|
|
21
|
+
var _binding$arg;
|
|
22
|
+
const config = {
|
|
23
|
+
...DEFAULT_CONFIG,
|
|
24
|
+
...((_binding$arg = binding.arg) !== null && _binding$arg !== void 0 ? _binding$arg : {})
|
|
25
|
+
};
|
|
26
|
+
el.textContent = '';
|
|
27
|
+
el.appendChild(sanitize(binding.value, config));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const clear = el => {
|
|
31
|
+
el.textContent = '';
|
|
32
|
+
};
|
|
33
|
+
const SafeHtmlDirective = {
|
|
34
|
+
bind: transform,
|
|
35
|
+
update: transform,
|
|
36
|
+
unbind: clear
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { SafeHtmlDirective };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const absoluteUrls = ['http://example.org', 'http://example.org:8080', 'https://example.org', 'https://example.org:8080', 'https://192.168.1.1', 'ftp://192.168.1.1', 'mailto:someone@example.com'];
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-script-url */
|
|
4
|
+
const javascriptUrls = ['javascript:', 'javascript:alert("XSS")', 'jav\tascript:alert("XSS");'];
|
|
5
|
+
/* eslint-disable no-script-url */
|
|
6
|
+
|
|
7
|
+
const encodedJavaScriptUrls = ['javascript:alert('XSS')', 'javascript:alert('XSS')', 'javascript:alert('XSS')', '  javascript:alert("XSS");'];
|
|
8
|
+
const relativeUrls = ['./relative/link', '../relative/link', '/relative/link', '/users/sign_in', '#docs/link', '#'];
|
|
9
|
+
|
|
10
|
+
export { absoluteUrls, encodedJavaScriptUrls, javascriptUrls, relativeUrls };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
|
|
3
|
+
const getBaseURL = () => {
|
|
4
|
+
const {
|
|
5
|
+
protocol,
|
|
6
|
+
host
|
|
7
|
+
} = window.location;
|
|
8
|
+
return `${protocol}//${host}`;
|
|
9
|
+
};
|
|
10
|
+
const isExternalURL = (target, hostname) => {
|
|
11
|
+
return target === '_blank' && hostname !== window.location.hostname;
|
|
12
|
+
};
|
|
13
|
+
const secureRel = rel => {
|
|
14
|
+
const rels = rel ? rel.trim().split(' ') : [];
|
|
15
|
+
if (!rels.includes('noopener')) {
|
|
16
|
+
rels.push('noopener');
|
|
17
|
+
}
|
|
18
|
+
if (!rels.includes('noreferrer')) {
|
|
19
|
+
rels.push('noreferrer');
|
|
20
|
+
}
|
|
21
|
+
return rels.join(' ');
|
|
22
|
+
};
|
|
23
|
+
const isSafeURL = url => {
|
|
24
|
+
try {
|
|
25
|
+
const parsedURL = new URL(url, getBaseURL());
|
|
26
|
+
return ['http:', 'https:', 'mailto:', 'ftp:'].includes(parsedURL.protocol);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const transform = function (el) {
|
|
32
|
+
let {
|
|
33
|
+
arg: {
|
|
34
|
+
skipSanitization = false
|
|
35
|
+
} = {}
|
|
36
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
37
|
+
if (skipSanitization) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const {
|
|
41
|
+
href,
|
|
42
|
+
target,
|
|
43
|
+
rel,
|
|
44
|
+
hostname
|
|
45
|
+
} = el;
|
|
46
|
+
if (!isSafeURL(href)) {
|
|
47
|
+
el.href = 'about:blank';
|
|
48
|
+
}
|
|
49
|
+
if (isExternalURL(target, hostname)) {
|
|
50
|
+
el.rel = secureRel(rel);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const SafeLinkDirective = {
|
|
54
|
+
inserted: transform,
|
|
55
|
+
update: function () {
|
|
56
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
57
|
+
args[_key] = arguments[_key];
|
|
58
|
+
}
|
|
59
|
+
Vue.nextTick(() => {
|
|
60
|
+
transform(...args);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { SafeLinkDirective };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VBTooltip as GlTooltipDirective } from 'bootstrap-vue/esm/index.js';
|