@gitlab/ui 98.4.0 → 98.5.0

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
+ # [98.5.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v98.4.0...v98.5.0) (2024-10-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * **DuoChatMessage:** add max height for code blocks in messages ([4493ca9](https://gitlab.com/gitlab-org/gitlab-ui/commit/4493ca9fca716aee2c4fb7b06abe0e90f60aa7e0))
7
+
1
8
  # [98.4.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v98.3.0...v98.4.0) (2024-10-24)
2
9
 
3
10
 
@@ -0,0 +1,5 @@
1
+ const DUO_CODE_SCRIM_TOP_CLASS = 'scrim-top';
2
+ const DUO_CODE_SCRIM_BOTTOM_CLASS = 'scrim-bottom';
3
+ const DUO_CODE_SCRIM_OFFSET = 16;
4
+
5
+ export { DUO_CODE_SCRIM_BOTTOM_CLASS, DUO_CODE_SCRIM_OFFSET, DUO_CODE_SCRIM_TOP_CLASS };
@@ -1,3 +1,4 @@
1
+ import throttle from 'lodash/throttle';
1
2
  import GlIcon from '../../../../../base/icon/icon';
2
3
  import GlLoadingIcon from '../../../../../base/loading_icon/loading_icon';
3
4
  import { GlTooltipDirective } from '../../../../../../directives/tooltip';
@@ -13,6 +14,7 @@ import { renderDuoChatMarkdownPreview } from '../../markdown_renderer';
13
14
  import { CopyCodeElement } from './copy_code_element';
14
15
  import { InsertCodeSnippetElement } from './insert_code_snippet_element';
15
16
  import { concatUntilEmpty } from './utils';
17
+ import { DUO_CODE_SCRIM_BOTTOM_CLASS, DUO_CODE_SCRIM_OFFSET, DUO_CODE_SCRIM_TOP_CLASS } from './constants';
16
18
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
17
19
 
18
20
  const i18n = {
@@ -195,6 +197,7 @@ var script = {
195
197
  if (!this.isChunk && this.$refs.content) {
196
198
  this.$nextTick(this.renderGFM(this.$refs.content));
197
199
  }
200
+ this.detectScrollableCodeBlocks();
198
201
  },
199
202
  logEvent(e) {
200
203
  this.$emit('track-feedback', {
@@ -218,6 +221,27 @@ var script = {
218
221
  messageId: this.message.id,
219
222
  contextItem
220
223
  });
224
+ },
225
+ detectScrollableCodeBlocks() {
226
+ const codeBlocks = document.querySelectorAll('.duo-chat-message pre');
227
+ codeBlocks.forEach(e => {
228
+ if (e.scrollHeight > e.offsetHeight) {
229
+ e.classList.add(DUO_CODE_SCRIM_BOTTOM_CLASS);
230
+ e.addEventListener('scroll', throttle(() => this.toggleScrolling(e), 200));
231
+ }
232
+ });
233
+ },
234
+ toggleScrolling(e) {
235
+ if (e.scrollHeight - e.scrollTop <= e.offsetHeight + DUO_CODE_SCRIM_OFFSET) {
236
+ e.classList.remove(DUO_CODE_SCRIM_BOTTOM_CLASS);
237
+ } else {
238
+ e.classList.add(DUO_CODE_SCRIM_BOTTOM_CLASS);
239
+ }
240
+ if (e.scrollTop > DUO_CODE_SCRIM_OFFSET) {
241
+ e.classList.add(DUO_CODE_SCRIM_TOP_CLASS);
242
+ } else {
243
+ e.classList.remove(DUO_CODE_SCRIM_TOP_CLASS);
244
+ }
221
245
  }
222
246
  }
223
247
  };