@gitlab/ui 108.8.0 → 108.8.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,10 @@
1
+ ## [108.8.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v108.8.0...v108.8.1) (2025-02-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **GlTruncate:** Prevent total whitespace collapse ([2811b7e](https://gitlab.com/gitlab-org/gitlab-ui/commit/2811b7e7e9a7fc37bd17042063ee3e4504cb380d))
7
+
1
8
  # [108.8.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v108.7.0...v108.8.0) (2025-02-27)
2
9
 
3
10
 
@@ -3,5 +3,6 @@ const POSITION = {
3
3
  MIDDLE: 'middle',
4
4
  END: 'end'
5
5
  };
6
+ const ZERO_WIDTH_SPACE = '\u200b';
6
7
 
7
- export { POSITION };
8
+ export { POSITION, ZERO_WIDTH_SPACE };
@@ -1,6 +1,6 @@
1
1
  import { GlTooltipDirective } from '../../../directives/tooltip';
2
2
  import { GlResizeObserverDirective } from '../../../directives/resize_observer/resize_observer';
3
- import { POSITION } from './constants';
3
+ import { POSITION, ZERO_WIDTH_SPACE } from './constants';
4
4
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
5
5
 
6
6
  //
@@ -46,8 +46,49 @@ var script = {
46
46
  middleIndex() {
47
47
  return Math.floor(this.text.length / 2);
48
48
  },
49
+ preventWhitespaceCollapse() {
50
+ // We don't use `\s` here since it includes non-breaking spaces and other
51
+ // non-collapsible whitespace characters.
52
+ // See https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace
53
+ // and https://infra.spec.whatwg.org/#ascii-whitespace.
54
+ const collapsibleWhitespaceChar = /^[ \n\t\r\f]$/;
55
+ const {
56
+ text,
57
+ middleIndex
58
+ } = this;
59
+ const lastCharOfFirstIsCollapsibleWhitespace = collapsibleWhitespaceChar.test(text.charAt(middleIndex - 1));
60
+ const firstCharOfLastIsCollapsibleWhitespace = collapsibleWhitespaceChar.test(text.charAt(middleIndex));
61
+ return lastCharOfFirstIsCollapsibleWhitespace && !firstCharOfLastIsCollapsibleWhitespace;
62
+ },
49
63
  first() {
50
- return this.text.slice(0, this.middleIndex);
64
+ const first = this.text.slice(0, this.middleIndex);
65
+ if (this.preventWhitespaceCollapse) {
66
+ // Because this component's root element has an internal flex layout,
67
+ // whitespace at the end of the first child span and at the beginning
68
+ // of the second child span would be ignored (i.e., totally collapsed).
69
+ //
70
+ // This means that strings with a space character in the middle would
71
+ // render as if there were no space, which would be incorrect (e.g.,
72
+ // "Gap here" would render as "Gaphere").
73
+ //
74
+ // So, in that case, we insert a zero-width space at the end of the
75
+ // first child span to prevent that whitespace from being totally
76
+ // collapsed. In other words:
77
+ // 'first-part-with-space ' → 'first-part-with-space ​'
78
+ //
79
+ // If there's a whitespace character at the begging of the second child
80
+ // span, we do *not* do this, since the left-to-right mark (‎) just
81
+ // before `{{ last }}` in the template prevents the collapse of any
82
+ // whitespace at the start of `last`. If we ignored this edge case,
83
+ // we'd render a double space, which wouldn't correspond to how the
84
+ // string would normally render.
85
+ //
86
+ // See
87
+ // https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace#whitespace_in_block_formatting_contexts
88
+ // for more information on how browsers treat whitespace.
89
+ return `${first}${ZERO_WIDTH_SPACE}`;
90
+ }
91
+ return first;
51
92
  },
52
93
  last() {
53
94
  return this.text.slice(this.middleIndex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "108.8.0",
3
+ "version": "108.8.1",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -144,7 +144,7 @@
144
144
  "axe-playwright": "^2.1.0",
145
145
  "babel-jest": "29.0.1",
146
146
  "babel-loader": "^8.0.5",
147
- "cypress": "14.0.0",
147
+ "cypress": "14.0.2",
148
148
  "cypress-axe": "^1.4.0",
149
149
  "cypress-real-events": "^1.11.0",
150
150
  "dompurify": "^3.1.2",
@@ -3,3 +3,5 @@ export const POSITION = {
3
3
  MIDDLE: 'middle',
4
4
  END: 'end',
5
5
  };
6
+
7
+ export const ZERO_WIDTH_SPACE = '\u200b';
@@ -2,7 +2,7 @@
2
2
  <script>
3
3
  import { GlTooltipDirective } from '../../../directives/tooltip';
4
4
  import { GlResizeObserverDirective } from '../../../directives/resize_observer/resize_observer';
5
- import { POSITION } from './constants';
5
+ import { POSITION, ZERO_WIDTH_SPACE } from './constants';
6
6
 
7
7
  export default {
8
8
  name: 'GlTruncate',
@@ -47,8 +47,53 @@ export default {
47
47
  return Math.floor(this.text.length / 2);
48
48
  },
49
49
 
50
+ preventWhitespaceCollapse() {
51
+ // We don't use `\s` here since it includes non-breaking spaces and other
52
+ // non-collapsible whitespace characters.
53
+ // See https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace
54
+ // and https://infra.spec.whatwg.org/#ascii-whitespace.
55
+ const collapsibleWhitespaceChar = /^[ \n\t\r\f]$/;
56
+ const { text, middleIndex } = this;
57
+ const lastCharOfFirstIsCollapsibleWhitespace = collapsibleWhitespaceChar.test(
58
+ text.charAt(middleIndex - 1)
59
+ );
60
+ const firstCharOfLastIsCollapsibleWhitespace = collapsibleWhitespaceChar.test(
61
+ text.charAt(middleIndex)
62
+ );
63
+
64
+ return lastCharOfFirstIsCollapsibleWhitespace && !firstCharOfLastIsCollapsibleWhitespace;
65
+ },
50
66
  first() {
51
- return this.text.slice(0, this.middleIndex);
67
+ const first = this.text.slice(0, this.middleIndex);
68
+
69
+ if (this.preventWhitespaceCollapse) {
70
+ // Because this component's root element has an internal flex layout,
71
+ // whitespace at the end of the first child span and at the beginning
72
+ // of the second child span would be ignored (i.e., totally collapsed).
73
+ //
74
+ // This means that strings with a space character in the middle would
75
+ // render as if there were no space, which would be incorrect (e.g.,
76
+ // "Gap here" would render as "Gaphere").
77
+ //
78
+ // So, in that case, we insert a zero-width space at the end of the
79
+ // first child span to prevent that whitespace from being totally
80
+ // collapsed. In other words:
81
+ // 'first-part-with-space ' → 'first-part-with-space &ZeroWidthSpace;'
82
+ //
83
+ // If there's a whitespace character at the begging of the second child
84
+ // span, we do *not* do this, since the left-to-right mark (&lrm;) just
85
+ // before `{{ last }}` in the template prevents the collapse of any
86
+ // whitespace at the start of `last`. If we ignored this edge case,
87
+ // we'd render a double space, which wouldn't correspond to how the
88
+ // string would normally render.
89
+ //
90
+ // See
91
+ // https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace#whitespace_in_block_formatting_contexts
92
+ // for more information on how browsers treat whitespace.
93
+ return `${first}${ZERO_WIDTH_SPACE}`;
94
+ }
95
+
96
+ return first;
52
97
  },
53
98
  last() {
54
99
  return this.text.slice(this.middleIndex);