@gitlab/ui 65.0.1 → 65.1.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [65.1.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v65.1.0...v65.1.1) (2023-08-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **GlCollpasibleListbox:** correctly handle Home and End ([596127d](https://gitlab.com/gitlab-org/gitlab-ui/commit/596127d79c05f190746109ec9776ee7460672237))
7
+
8
+ # [65.1.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v65.0.1...v65.1.0) (2023-08-09)
9
+
10
+
11
+ ### Features
12
+
13
+ * **GlFormFields:** Add validator for emojis ([7f5b9aa](https://gitlab.com/gitlab-org/gitlab-ui/commit/7f5b9aa195b3a62a83b5b395aec2e49d08b87bcb))
14
+
1
15
  ## [65.0.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v65.0.0...v65.0.1) (2023-08-05)
2
16
 
3
17
 
@@ -1,3 +1,7 @@
1
+ import emojiRegex from 'emoji-regex';
2
+
3
+ const EMOJI_REGEX = emojiRegex();
4
+
1
5
  // This contains core validating behavior and **should not** contain
2
6
  // domain-specific validations.
3
7
  //
@@ -11,6 +15,34 @@
11
15
  // export const projectPathIsUnique = ...
12
16
  // ```
13
17
  const factory = (failMessage, isValid) => val => !isValid(val) ? failMessage : '';
18
+
19
+ /**
20
+ * Validator function to check if a string is present and non-empty.
21
+ *
22
+ * Returns an empty string if the input contains a valid string.
23
+ *
24
+ * Returns `failMessage` if the input string is empty, null, or undefined.
25
+ * @param {string} failMessage - The error message to be returned when validation fails.
26
+ * @returns {Function} A validation function that returns either `failMessage` or empty string.
27
+ */
14
28
  const required = failMessage => factory(failMessage, val => val !== '' && val !== null && val !== undefined);
15
29
 
16
- export { factory, required };
30
+ /**
31
+ * Validator function to check if a string contains any emojis.
32
+ *
33
+ * Returns an empty string if the input is empty, null, or undefined, or if no emoji is present.
34
+ *
35
+ * Returns `failMessage` if the input string contains at least one emoji.
36
+ * @param {string} failMessage - The error message to be returned when validation fails.
37
+ * @returns {Function} A validation function that returns either `failMessage` or empty string.
38
+ */
39
+ const noEmojis = failMessage => factory(failMessage, val => {
40
+ var _val$match$length, _val$match;
41
+ if (!val || typeof val !== 'string') {
42
+ return true;
43
+ }
44
+ const resultsLength = (_val$match$length = (_val$match = val.match(EMOJI_REGEX)) === null || _val$match === void 0 ? void 0 : _val$match.length) !== null && _val$match$length !== void 0 ? _val$match$length : 0;
45
+ return resultsLength < 1;
46
+ });
47
+
48
+ export { factory, noEmojis, required };
@@ -34,7 +34,6 @@ var script = {
34
34
  href: item.href,
35
35
  ...item.extraAttrs
36
36
  },
37
- wrapperClass: item.wrapperClass,
38
37
  listeners: {
39
38
  click: this.action
40
39
  }
@@ -51,8 +50,7 @@ var script = {
51
50
  item === null || item === void 0 ? void 0 : (_item$action = item.action) === null || _item$action === void 0 ? void 0 : _item$action.call(undefined, item);
52
51
  this.action();
53
52
  }
54
- },
55
- wrapperClass: item === null || item === void 0 ? void 0 : item.wrapperClass
53
+ }
56
54
  };
57
55
  },
58
56
  listIndex() {
@@ -63,6 +61,10 @@ var script = {
63
61
  var _this$item3, _this$item3$extraAttr;
64
62
  return (_this$item3 = this.item) !== null && _this$item3 !== void 0 && (_this$item3$extraAttr = _this$item3.extraAttrs) !== null && _this$item3$extraAttr !== void 0 && _this$item3$extraAttr.disabled ? null : -1;
65
63
  },
64
+ wrapperClass() {
65
+ var _this$item$wrapperCla, _this$item4;
66
+ return (_this$item$wrapperCla = (_this$item4 = this.item) === null || _this$item4 === void 0 ? void 0 : _this$item4.wrapperClass) !== null && _this$item$wrapperCla !== void 0 ? _this$item$wrapperCla : '';
67
+ },
66
68
  wrapperListeners() {
67
69
  const listeners = {
68
70
  keydown: this.onKeydown
@@ -105,7 +107,7 @@ var script = {
105
107
  const __vue_script__ = script;
106
108
 
107
109
  /* template */
108
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('li',_vm._g({class:[_vm.$options.ITEM_CLASS, _vm.itemComponent.wrapperClass],attrs:{"tabindex":_vm.listIndex,"data-testid":"disclosure-dropdown-item"}},_vm.wrapperListeners),[_vm._t("default",function(){return [_c(_vm.itemComponent.is,_vm._g(_vm._b({ref:"item",tag:"component",staticClass:"gl-new-dropdown-item-content",attrs:{"tabindex":_vm.componentIndex}},'component',_vm.itemComponent.attrs,false),_vm.itemComponent.listeners),[_c('span',{staticClass:"gl-new-dropdown-item-text-wrapper"},[_vm._t("list-item",function(){return [_vm._v("\n "+_vm._s(_vm.item.text)+"\n ")]})],2)])]})],2)};
110
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('li',_vm._g({class:[_vm.$options.ITEM_CLASS, _vm.wrapperClass],attrs:{"tabindex":_vm.listIndex,"data-testid":"disclosure-dropdown-item"}},_vm.wrapperListeners),[_vm._t("default",function(){return [_c(_vm.itemComponent.is,_vm._g(_vm._b({ref:"item",tag:"component",staticClass:"gl-new-dropdown-item-content",attrs:{"tabindex":_vm.componentIndex}},'component',_vm.itemComponent.attrs,false),_vm.itemComponent.listeners),[_c('span',{staticClass:"gl-new-dropdown-item-text-wrapper"},[_vm._t("list-item",function(){return [_vm._v("\n "+_vm._s(_vm.item.text)+"\n ")]})],2)])]})],2)};
109
111
  var __vue_staticRenderFns__ = [];
110
112
 
111
113
  /* style */
@@ -545,8 +545,14 @@ var script = {
545
545
  let stop = true;
546
546
  const isSearchInput = target.matches(SEARCH_INPUT_SELECTOR);
547
547
  if (code === HOME) {
548
+ if (isSearchInput) {
549
+ return;
550
+ }
548
551
  this.focusItem(0, elements);
549
552
  } else if (code === END) {
553
+ if (isSearchInput) {
554
+ return;
555
+ }
550
556
  this.focusItem(elements.length - 1, elements);
551
557
  } else if (code === ARROW_UP) {
552
558
  if (isSearchInput) {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Sat, 05 Aug 2023 22:20:46 GMT
3
+ * Generated on Thu, 10 Aug 2023 14:55:51 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Sat, 05 Aug 2023 22:20:46 GMT
3
+ * Generated on Thu, 10 Aug 2023 14:55:51 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Sat, 05 Aug 2023 22:20:46 GMT
3
+ * Generated on Thu, 10 Aug 2023 14:55:51 GMT
4
4
  */
5
5
 
6
6
  export const BLACK = "#fff";
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Sat, 05 Aug 2023 22:20:46 GMT
3
+ * Generated on Thu, 10 Aug 2023 14:55:51 GMT
4
4
  */
5
5
 
6
6
  export const BLACK = "#000";
@@ -1,6 +1,6 @@
1
1
 
2
2
  // Do not edit directly
3
- // Generated on Sat, 05 Aug 2023 22:20:46 GMT
3
+ // Generated on Thu, 10 Aug 2023 14:55:51 GMT
4
4
 
5
5
  $red-950: #fff4f3;
6
6
  $red-900: #fcf1ef;
@@ -1,6 +1,6 @@
1
1
 
2
2
  // Do not edit directly
3
- // Generated on Sat, 05 Aug 2023 22:20:46 GMT
3
+ // Generated on Thu, 10 Aug 2023 14:55:51 GMT
4
4
 
5
5
  $brand-gray-05: #2b2838 !default;
6
6
  $brand-gray-04: #45424d !default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "65.0.1",
3
+ "version": "65.1.1",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -91,7 +91,7 @@
91
91
  "@gitlab/eslint-plugin": "19.0.0",
92
92
  "@gitlab/fonts": "^1.2.0",
93
93
  "@gitlab/stylelint-config": "4.1.0",
94
- "@gitlab/svgs": "3.58.0",
94
+ "@gitlab/svgs": "3.59.0",
95
95
  "@rollup/plugin-commonjs": "^11.1.0",
96
96
  "@rollup/plugin-node-resolve": "^7.1.3",
97
97
  "@rollup/plugin-replace": "^2.3.2",
@@ -118,7 +118,7 @@
118
118
  "babel-loader": "^8.0.5",
119
119
  "babel-plugin-require-context-hook": "^1.0.0",
120
120
  "bootstrap": "4.6.2",
121
- "cypress": "12.17.2",
121
+ "cypress": "12.17.3",
122
122
  "dompurify": "^2.4.7",
123
123
  "emoji-regex": "^10.0.0",
124
124
  "eslint": "8.46.0",
@@ -1,3 +1,7 @@
1
+ import emojiRegex from 'emoji-regex';
2
+
3
+ const EMOJI_REGEX = emojiRegex();
4
+
1
5
  // This contains core validating behavior and **should not** contain
2
6
  // domain-specific validations.
3
7
  //
@@ -12,5 +16,34 @@
12
16
  // ```
13
17
  export const factory = (failMessage, isValid) => (val) => !isValid(val) ? failMessage : '';
14
18
 
19
+ /**
20
+ * Validator function to check if a string is present and non-empty.
21
+ *
22
+ * Returns an empty string if the input contains a valid string.
23
+ *
24
+ * Returns `failMessage` if the input string is empty, null, or undefined.
25
+ * @param {string} failMessage - The error message to be returned when validation fails.
26
+ * @returns {Function} A validation function that returns either `failMessage` or empty string.
27
+ */
15
28
  export const required = (failMessage) =>
16
29
  factory(failMessage, (val) => val !== '' && val !== null && val !== undefined);
30
+
31
+ /**
32
+ * Validator function to check if a string contains any emojis.
33
+ *
34
+ * Returns an empty string if the input is empty, null, or undefined, or if no emoji is present.
35
+ *
36
+ * Returns `failMessage` if the input string contains at least one emoji.
37
+ * @param {string} failMessage - The error message to be returned when validation fails.
38
+ * @returns {Function} A validation function that returns either `failMessage` or empty string.
39
+ */
40
+ export const noEmojis = (failMessage) =>
41
+ factory(failMessage, (val) => {
42
+ if (!val || typeof val !== 'string') {
43
+ return true;
44
+ }
45
+
46
+ const resultsLength = val.match(EMOJI_REGEX)?.length ?? 0;
47
+
48
+ return resultsLength < 1;
49
+ });
@@ -1,4 +1,4 @@
1
- import { required } from './validators';
1
+ import { noEmojis, required } from './validators';
2
2
 
3
3
  const TEST_FAIL_MESSAGE = 'Yo test failed!';
4
4
 
@@ -26,4 +26,31 @@ describe('components/base/form/form_fields/validators', () => {
26
26
  expect(validator(input)).toBe(output);
27
27
  });
28
28
  });
29
+
30
+ describe('noEmojis', () => {
31
+ let validator;
32
+
33
+ beforeEach(() => {
34
+ validator = noEmojis(TEST_FAIL_MESSAGE);
35
+ });
36
+
37
+ it.each`
38
+ input | output
39
+ ${'123🐱'} | ${TEST_FAIL_MESSAGE}
40
+ ${'0 🍩'} | ${TEST_FAIL_MESSAGE}
41
+ ${'🐟'} | ${TEST_FAIL_MESSAGE}
42
+ ${''} | ${''}
43
+ ${null} | ${''}
44
+ ${undefined} | ${''}
45
+ ${'123'} | ${''}
46
+ ${'0'} | ${''}
47
+ ${{}} | ${''}
48
+ ${0} | ${''}
49
+ ${1} | ${''}
50
+ ${true} | ${''}
51
+ ${false} | ${''}
52
+ `('with $input, returns $output', ({ input, output }) => {
53
+ expect(validator(input)).toBe(output);
54
+ });
55
+ });
29
56
  });
@@ -34,7 +34,6 @@ export default {
34
34
  href: item.href,
35
35
  ...item.extraAttrs,
36
36
  },
37
- wrapperClass: item.wrapperClass,
38
37
  listeners: {
39
38
  click: this.action,
40
39
  },
@@ -52,7 +51,6 @@ export default {
52
51
  this.action();
53
52
  },
54
53
  },
55
- wrapperClass: item?.wrapperClass,
56
54
  };
57
55
  },
58
56
  listIndex() {
@@ -61,6 +59,9 @@ export default {
61
59
  componentIndex() {
62
60
  return this.item?.extraAttrs?.disabled ? null : -1;
63
61
  },
62
+ wrapperClass() {
63
+ return this.item?.wrapperClass ?? '';
64
+ },
64
65
  wrapperListeners() {
65
66
  const listeners = {
66
67
  keydown: this.onKeydown,
@@ -100,7 +101,7 @@ export default {
100
101
  <template>
101
102
  <li
102
103
  :tabindex="listIndex"
103
- :class="[$options.ITEM_CLASS, itemComponent.wrapperClass]"
104
+ :class="[$options.ITEM_CLASS, wrapperClass]"
104
105
  data-testid="disclosure-dropdown-item"
105
106
  v-on="wrapperListeners"
106
107
  >
@@ -330,6 +330,14 @@ describe('GlCollapsibleListbox', () => {
330
330
  expect(searchboxInput.element).toHaveFocus();
331
331
  });
332
332
 
333
+ it('should not move focus away from the input on `HOME` and `END`', async () => {
334
+ expect(searchboxInput.element).toHaveFocus();
335
+ await searchboxInput.trigger('keydown', { code: HOME });
336
+ expect(searchboxInput.element).toHaveFocus();
337
+ await searchboxInput.trigger('keydown', { code: END });
338
+ expect(searchboxInput.element).toHaveFocus();
339
+ });
340
+
333
341
  describe('pressing Enter on the input', () => {
334
342
  const keydownSpy = jest.fn();
335
343
 
@@ -565,8 +565,14 @@ export default {
565
565
  const isSearchInput = target.matches(SEARCH_INPUT_SELECTOR);
566
566
 
567
567
  if (code === HOME) {
568
+ if (isSearchInput) {
569
+ return;
570
+ }
568
571
  this.focusItem(0, elements);
569
572
  } else if (code === END) {
573
+ if (isSearchInput) {
574
+ return;
575
+ }
570
576
  this.focusItem(elements.length - 1, elements);
571
577
  } else if (code === ARROW_UP) {
572
578
  if (isSearchInput) {