@gitlab/ui 68.2.1 → 68.4.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,17 @@
1
+ # [68.4.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v68.3.0...v68.4.0) (2023-11-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * **GlAlert, GlBroadcastMessage:** Add CSS variable overrides ([ed2754f](https://gitlab.com/gitlab-org/gitlab-ui/commit/ed2754f2711cdd1eb9d2fd0f5b903a4d77aeff85))
7
+
8
+ # [68.3.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v68.2.1...v68.3.0) (2023-11-10)
9
+
10
+
11
+ ### Features
12
+
13
+ * **GlDuoChat:** support for slash commands ([2d3eee1](https://gitlab.com/gitlab-org/gitlab-ui/commit/2d3eee10dd2b1d183111729c0484deb125847c0d))
14
+
1
15
  ## [68.2.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v68.2.0...v68.2.1) (2023-11-10)
2
16
 
3
17
 
@@ -1,5 +1,7 @@
1
1
  import throttle from 'lodash/throttle';
2
2
  import emptySvg from '@gitlab/svgs/dist/illustrations/empty-state/empty-activity-md.svg';
3
+ import GlDropdownItem from '../../../base/dropdown/dropdown_item';
4
+ import GlCard from '../../../base/card/card';
3
5
  import GlEmptyState from '../../../regions/empty_state/empty_state';
4
6
  import GlButton from '../../../base/button/button';
5
7
  import GlAlert from '../../../base/alert/alert';
@@ -27,6 +29,23 @@ const i18n = {
27
29
  CHAT_LEGAL_DISCLAIMER: "May provide inappropriate responses not representative of GitLab's views. Do not input personal data.",
28
30
  CHAT_DEFAULT_PREDEFINED_PROMPTS: ['How do I change my password in GitLab?', 'How do I fork a project?', 'How do I clone a repository?', 'How do I create a template?']
29
31
  };
32
+ const slashCommands = [{
33
+ name: '/reset',
34
+ shouldSubmit: true,
35
+ description: 'Reset conversation, ignore the previous messages.'
36
+ }, {
37
+ name: '/test',
38
+ shouldSubmit: false,
39
+ description: 'Write tests for the code snippet.'
40
+ }, {
41
+ name: '/refactor',
42
+ shouldSubmit: false,
43
+ description: 'Refactor the code snippet.'
44
+ }, {
45
+ name: '/explain',
46
+ shouldSubmit: false,
47
+ description: 'Explain the code snippet.'
48
+ }];
30
49
  const isMessage = item => Boolean(item) && (item === null || item === void 0 ? void 0 : item.role);
31
50
  const itemsValidator = items => items.every(isMessage);
32
51
  var script = {
@@ -42,7 +61,9 @@ var script = {
42
61
  GlExperimentBadge,
43
62
  GlDuoChatLoader,
44
63
  GlDuoChatPredefinedPrompts,
45
- GlDuoChatConversation
64
+ GlDuoChatConversation,
65
+ GlCard,
66
+ GlDropdownItem
46
67
  },
47
68
  directives: {
48
69
  SafeHtml: SafeHtmlDirective
@@ -121,13 +142,22 @@ var script = {
121
142
  type: String,
122
143
  required: false,
123
144
  default: i18n.CHAT_DEFAULT_TITLE
145
+ },
146
+ /**
147
+ * Whether the slash commands should be available to user when typing the prompt.
148
+ */
149
+ withSlashCommands: {
150
+ type: Boolean,
151
+ required: false,
152
+ default: false
124
153
  }
125
154
  },
126
155
  data() {
127
156
  return {
128
157
  isHidden: false,
129
158
  prompt: '',
130
- scrolledToBottom: true
159
+ scrolledToBottom: true,
160
+ activeCommandIndex: 0
131
161
  };
132
162
  },
133
163
  computed: {
@@ -152,6 +182,17 @@ var script = {
152
182
  }
153
183
  const lastMessage = this.messages[this.messages.length - 1];
154
184
  return lastMessage.content === CHAT_RESET_MESSAGE;
185
+ },
186
+ filteredSlashCommands() {
187
+ const caseInsensitivePrompt = this.prompt.toLowerCase();
188
+ return slashCommands.filter(c => c.name.toLowerCase().startsWith(caseInsensitivePrompt));
189
+ },
190
+ shouldShowSlashCommands() {
191
+ if (!this.withSlashCommands) return false;
192
+ const caseInsensitivePrompt = this.prompt.toLowerCase();
193
+ const startsWithSlash = caseInsensitivePrompt.startsWith('/');
194
+ const startsWithSlashCommand = slashCommands.some(c => caseInsensitivePrompt.startsWith(c.name));
195
+ return startsWithSlash && this.filteredSlashCommands.length && !startsWithSlashCommand;
155
196
  }
156
197
  },
157
198
  watch: {
@@ -215,6 +256,54 @@ var script = {
215
256
  * @param {*} event An event, containing the feedback choices and the extended feedback text.
216
257
  */
217
258
  this.$emit('track-feedback', event);
259
+ },
260
+ onInputKeyup(e) {
261
+ const {
262
+ metaKey,
263
+ ctrlKey,
264
+ altKey,
265
+ shiftKey
266
+ } = e;
267
+ if (this.shouldShowSlashCommands) {
268
+ e.preventDefault();
269
+ if (e.key === 'Enter') {
270
+ this.selectSlashCommand(this.activeCommandIndex);
271
+ } else if (e.key === 'ArrowUp') {
272
+ this.prevCommand();
273
+ } else if (e.key === 'ArrowDown') {
274
+ this.nextCommand();
275
+ } else {
276
+ this.activeCommandIndex = 0;
277
+ }
278
+ } else if (e.key === 'Enter' && !(metaKey || ctrlKey || altKey || shiftKey)) {
279
+ e.preventDefault();
280
+ this.sendChatPrompt();
281
+ }
282
+ },
283
+ prevCommand() {
284
+ this.activeCommandIndex -= 1;
285
+ this.wrapCommandIndex();
286
+ },
287
+ nextCommand() {
288
+ this.activeCommandIndex += 1;
289
+ this.wrapCommandIndex();
290
+ },
291
+ wrapCommandIndex() {
292
+ if (this.activeCommandIndex < 0) {
293
+ this.activeCommandIndex = this.filteredSlashCommands.length - 1;
294
+ } else if (this.activeCommandIndex >= this.filteredSlashCommands.length) {
295
+ this.activeCommandIndex = 0;
296
+ }
297
+ },
298
+ selectSlashCommand(index) {
299
+ const command = this.filteredSlashCommands[index];
300
+ if (command.shouldSubmit) {
301
+ this.prompt = command.name;
302
+ this.sendChatPrompt();
303
+ } else {
304
+ this.prompt = `${command.name} `;
305
+ this.$refs.prompt.$el.focus();
306
+ }
218
307
  }
219
308
  },
220
309
  i18n,
@@ -229,7 +318,7 @@ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=
229
318
  {
230
319
  'gl-h-full': !_vm.hasMessages,
231
320
  'gl-h-auto': _vm.hasMessages,
232
- } ],attrs:{"tag":"div","name":"message"}},[_vm._l((_vm.conversations),function(conversation,index){return _c('gl-duo-chat-conversation',{key:("conversation-" + index),attrs:{"messages":conversation,"show-delimiter":index > 0},on:{"track-feedback":_vm.onTrackFeedback}})}),_vm._v(" "),(!_vm.hasMessages && !_vm.isLoading)?[_c('div',{key:"empty-state",staticClass:"gl-display-flex gl-flex-grow-1 gl-mr-auto gl-ml-auto"},[_c('gl-empty-state',{staticClass:"gl-align-self-center",attrs:{"svg-path":_vm.$options.emptySvg,"svg-height":145,"title":_vm.$options.i18n.CHAT_EMPTY_STATE_TITLE,"description":_vm.$options.i18n.CHAT_EMPTY_STATE_DESC}})],1),_vm._v(" "),_c('gl-duo-chat-predefined-prompts',{key:"predefined-prompts",attrs:{"prompts":_vm.predefinedPrompts},on:{"click":_vm.sendPredefinedPrompt}})]:_vm._e()],2),_vm._v(" "),_c('transition',{attrs:{"name":"loader"}},[(_vm.isLoading)?_c('gl-duo-chat-loader',{staticClass:"gl-px-0!",attrs:{"tool-name":_vm.toolName}}):_vm._e()],1)],1)],2),_vm._v(" "),(_vm.isChatAvailable)?_c('footer',{staticClass:"gl-drawer-footer gl-drawer-footer-sticky gl-p-5 gl-border-t gl-bg-gray-10",class:{ 'gl-drawer-body-scrim-on-footer': !_vm.scrolledToBottom },attrs:{"data-testid":"chat-footer"}},[_c('gl-form',{attrs:{"data-testid":"chat-prompt-form"},on:{"submit":function($event){$event.stopPropagation();$event.preventDefault();return _vm.sendChatPrompt.apply(null, arguments)}}},[_c('gl-form-input-group',{scopedSlots:_vm._u([{key:"append",fn:function(){return [_c('gl-button',{staticClass:"gl-absolute! gl-bottom-2 gl-right-2 gl-rounded-base!",attrs:{"icon":"paper-airplane","category":"primary","variant":"confirm","type":"submit","aria-label":_vm.$options.i18n.CHAT_SUBMIT_LABEL,"disabled":_vm.isLoading}})]},proxy:true}],null,false,2232229068)},[_c('div',{staticClass:"duo-chat-input gl-flex-grow-1 gl-vertical-align-top gl-max-w-full gl-min-h-8 gl-inset-border-1-gray-400 gl-rounded-base gl-bg-white",attrs:{"data-value":_vm.prompt}},[_c('gl-form-textarea',{staticClass:"gl-absolute gl-h-full! gl-py-4! gl-bg-transparent! gl-rounded-top-right-none gl-rounded-bottom-right-none gl-shadow-none!",class:{ 'gl-text-truncate': !_vm.prompt },attrs:{"data-testid":"chat-prompt-input","placeholder":_vm.$options.i18n.CHAT_PROMPT_PLACEHOLDER,"disabled":_vm.isLoading,"autofocus":""},nativeOn:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey||$event.metaKey){ return null; }$event.preventDefault();return _vm.sendChatPrompt.apply(null, arguments)}},model:{value:(_vm.prompt),callback:function ($$v) {_vm.prompt=$$v;},expression:"prompt"}})],1)]),_vm._v(" "),_c('gl-form-text',{staticClass:"gl-text-gray-400 gl-line-height-20 gl-mt-3",attrs:{"data-testid":"chat-legal-disclaimer"}},[_vm._v(_vm._s(_vm.$options.i18n.CHAT_LEGAL_DISCLAIMER))])],1)],1):_vm._e()]):_vm._e()};
321
+ } ],attrs:{"tag":"div","name":"message"}},[_vm._l((_vm.conversations),function(conversation,index){return _c('gl-duo-chat-conversation',{key:("conversation-" + index),attrs:{"messages":conversation,"show-delimiter":index > 0},on:{"track-feedback":_vm.onTrackFeedback}})}),_vm._v(" "),(!_vm.hasMessages && !_vm.isLoading)?[_c('div',{key:"empty-state",staticClass:"gl-display-flex gl-flex-grow-1 gl-mr-auto gl-ml-auto"},[_c('gl-empty-state',{staticClass:"gl-align-self-center",attrs:{"svg-path":_vm.$options.emptySvg,"svg-height":145,"title":_vm.$options.i18n.CHAT_EMPTY_STATE_TITLE,"description":_vm.$options.i18n.CHAT_EMPTY_STATE_DESC}})],1),_vm._v(" "),_c('gl-duo-chat-predefined-prompts',{key:"predefined-prompts",attrs:{"prompts":_vm.predefinedPrompts},on:{"click":_vm.sendPredefinedPrompt}})]:_vm._e()],2),_vm._v(" "),_c('transition',{attrs:{"name":"loader"}},[(_vm.isLoading)?_c('gl-duo-chat-loader',{staticClass:"gl-px-0!",attrs:{"tool-name":_vm.toolName}}):_vm._e()],1)],1)],2),_vm._v(" "),(_vm.isChatAvailable)?_c('footer',{staticClass:"gl-drawer-footer gl-drawer-footer-sticky gl-p-5 gl-border-t gl-bg-gray-10",class:{ 'gl-drawer-body-scrim-on-footer': !_vm.scrolledToBottom },attrs:{"data-testid":"chat-footer"}},[_c('gl-form',{attrs:{"data-testid":"chat-prompt-form"},on:{"submit":function($event){$event.stopPropagation();$event.preventDefault();return _vm.sendChatPrompt.apply(null, arguments)}}},[_c('gl-form-input-group',{scopedSlots:_vm._u([{key:"append",fn:function(){return [_c('gl-button',{staticClass:"gl-absolute! gl-bottom-2 gl-right-2 gl-rounded-base!",attrs:{"icon":"paper-airplane","category":"primary","variant":"confirm","type":"submit","aria-label":_vm.$options.i18n.CHAT_SUBMIT_LABEL,"disabled":_vm.isLoading}})]},proxy:true}],null,false,2232229068)},[_c('div',{staticClass:"duo-chat-input gl-flex-grow-1 gl-vertical-align-top gl-max-w-full gl-min-h-8 gl-inset-border-1-gray-400 gl-rounded-base gl-bg-white",attrs:{"data-value":_vm.prompt}},[(_vm.shouldShowSlashCommands)?_c('gl-card',{ref:"commands",staticClass:"slash-commands gl-absolute! gl-translate-y-n100 gl-list-style-none gl-pl-0 gl-w-full gl-shadow-md",attrs:{"body-class":"gl-p-2!"}},_vm._l((_vm.filteredSlashCommands),function(command,index){return _c('gl-dropdown-item',{key:command.name,class:{ 'active-command': index === _vm.activeCommandIndex },on:{"click":function($event){return _vm.selectSlashCommand(index)}},nativeOn:{"mouseenter":function($event){_vm.activeCommandIndex = index;}}},[_c('span',{staticClass:"gl-display-flex gl-justify-content-space-between"},[_c('span',{staticClass:"gl-display-block"},[_vm._v(_vm._s(command.name))]),_vm._v(" "),_c('small',{staticClass:"gl-text-gray-500 gl-font-style-italic"},[_vm._v(_vm._s(command.description))])])])}),1):_vm._e(),_vm._v(" "),_c('gl-form-textarea',{ref:"prompt",staticClass:"gl-absolute gl-h-full! gl-py-4! gl-bg-transparent! gl-rounded-top-right-none gl-rounded-bottom-right-none gl-shadow-none!",class:{ 'gl-text-truncate': !_vm.prompt },attrs:{"data-testid":"chat-prompt-input","placeholder":_vm.$options.i18n.CHAT_PROMPT_PLACEHOLDER,"disabled":_vm.isLoading,"autofocus":""},nativeOn:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey||$event.metaKey){ return null; }$event.preventDefault();},"keyup":function($event){return _vm.onInputKeyup.apply(null, arguments)}},model:{value:(_vm.prompt),callback:function ($$v) {_vm.prompt=$$v;},expression:"prompt"}})],1)]),_vm._v(" "),_c('gl-form-text',{staticClass:"gl-text-gray-400 gl-line-height-20 gl-mt-3",attrs:{"data-testid":"chat-legal-disclaimer"}},[_vm._v(_vm._s(_vm.$options.i18n.CHAT_LEGAL_DISCLAIMER))])],1)],1):_vm._e()]):_vm._e()};
233
322
  var __vue_staticRenderFns__ = [];
234
323
 
235
324
  /* style */
@@ -262,4 +351,4 @@ var __vue_staticRenderFns__ = [];
262
351
  );
263
352
 
264
353
  export default __vue_component__;
265
- export { i18n };
354
+ export { i18n, slashCommands };