@gitlab/ui 91.8.0 → 91.9.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 +7 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message/insert_code_snippet_element.js +43 -7
- package/dist/components/experimental/duo/chat/duo_chat.js +4 -0
- package/dist/components/experimental/duo/chat/mock_data.js +0 -2
- package/package.json +1 -1
- package/src/components/experimental/duo/chat/components/duo_chat_message/insert_code_snippet_element.js +35 -10
- package/src/components/experimental/duo/chat/duo_chat.vue +4 -0
- package/src/components/experimental/duo/chat/mock_data.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [91.9.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v91.8.0...v91.9.0) (2024-09-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **GlDuoChat:** make insert code snippet work with server-generated elements ([ce66a88](https://gitlab.com/gitlab-org/gitlab-ui/commit/ce66a88f7a477d5120c70633850106e8a8c1200e))
|
|
7
|
+
|
|
1
8
|
# [91.8.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v91.7.0...v91.8.0) (2024-09-04)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,19 +1,55 @@
|
|
|
1
1
|
import { createButton } from './buttons_utils';
|
|
2
2
|
|
|
3
|
+
function _assertClassBrand(e, t, n) {
|
|
4
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
5
|
+
throw new TypeError("Private element is not present on this object");
|
|
6
|
+
}
|
|
7
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
8
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
9
|
+
}
|
|
10
|
+
function _classPrivateFieldGet2(s, a) {
|
|
11
|
+
return s.get(_assertClassBrand(s, a));
|
|
12
|
+
}
|
|
13
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
14
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
15
|
+
}
|
|
16
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
17
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const CODE_MARKDOWN_CLASS = 'js-markdown-code';
|
|
21
|
+
var _actionButton = /*#__PURE__*/new WeakMap();
|
|
22
|
+
var _codeBlock = /*#__PURE__*/new WeakMap();
|
|
23
|
+
var _handleClick = /*#__PURE__*/new WeakMap();
|
|
3
24
|
class InsertCodeSnippetElement extends HTMLElement {
|
|
4
25
|
constructor(codeBlock) {
|
|
5
26
|
super();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
wrapper.dispatchEvent(new CustomEvent('insert-code-snippet', {
|
|
27
|
+
_classPrivateFieldInitSpec(this, _actionButton, void 0);
|
|
28
|
+
_classPrivateFieldInitSpec(this, _codeBlock, void 0);
|
|
29
|
+
_classPrivateFieldInitSpec(this, _handleClick, () => {
|
|
30
|
+
if (_classPrivateFieldGet2(_codeBlock, this)) {
|
|
31
|
+
_classPrivateFieldGet2(_codeBlock, this).dispatchEvent(new CustomEvent('insert-code-snippet', {
|
|
12
32
|
bubbles: true,
|
|
13
|
-
cancelable: true
|
|
33
|
+
cancelable: true,
|
|
34
|
+
detail: {
|
|
35
|
+
code: _classPrivateFieldGet2(_codeBlock, this).textContent.trim()
|
|
36
|
+
}
|
|
14
37
|
}));
|
|
15
38
|
}
|
|
16
39
|
});
|
|
40
|
+
_classPrivateFieldSet2(_actionButton, this, createButton());
|
|
41
|
+
|
|
42
|
+
// we handle two possible cases here:
|
|
43
|
+
// 1. we use constructor parameter if the element is created in Javscript and inserted in the document
|
|
44
|
+
// 2. we find the wrapping element containing code if the element is received from the server
|
|
45
|
+
_classPrivateFieldSet2(_codeBlock, this, codeBlock !== null && codeBlock !== void 0 ? codeBlock : this.closest(`.${CODE_MARKDOWN_CLASS}`));
|
|
46
|
+
}
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
this.appendChild(_classPrivateFieldGet2(_actionButton, this));
|
|
49
|
+
_classPrivateFieldGet2(_actionButton, this).addEventListener('click', _classPrivateFieldGet2(_handleClick, this));
|
|
50
|
+
}
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
_classPrivateFieldGet2(_actionButton, this).removeEventListener('click', _classPrivateFieldGet2(_handleClick, this));
|
|
17
53
|
}
|
|
18
54
|
}
|
|
19
55
|
|
|
@@ -419,6 +419,10 @@ var script = {
|
|
|
419
419
|
}
|
|
420
420
|
},
|
|
421
421
|
onInsertCodeSnippet(e) {
|
|
422
|
+
/**
|
|
423
|
+
* Emit insert-code-snippet event that clients can use to interact with a suggested code.
|
|
424
|
+
* @param {*} event An event containing code string in the "detail.code" field.
|
|
425
|
+
*/
|
|
422
426
|
this.$emit('insert-code-snippet', e);
|
|
423
427
|
}
|
|
424
428
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { setStoryTimeout } from '../../../../utils/test_utils';
|
|
2
|
-
import { InsertCodeSnippetElement } from './components/duo_chat_message/insert_code_snippet_element';
|
|
3
2
|
import { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES, CHAT_RESET_MESSAGE, CHAT_CLEAN_MESSAGE } from './constants';
|
|
4
3
|
import { getMockContextItems } from './components/duo_chat_context/mock_context_data';
|
|
5
4
|
|
|
@@ -135,7 +134,6 @@ const renderGFM = el => {
|
|
|
135
134
|
const codeBlock = el.querySelectorAll('.markdown-code-block');
|
|
136
135
|
codeBlock.forEach(block => {
|
|
137
136
|
block === null || block === void 0 ? void 0 : block.classList.add('gl-markdown', 'gl-compact-markdown');
|
|
138
|
-
block === null || block === void 0 ? void 0 : block.appendChild(new InsertCodeSnippetElement(block));
|
|
139
137
|
});
|
|
140
138
|
};
|
|
141
139
|
const SLASH_COMMANDS = [{
|
package/package.json
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
import { createButton } from './buttons_utils';
|
|
2
2
|
|
|
3
|
+
const CODE_MARKDOWN_CLASS = 'js-markdown-code';
|
|
4
|
+
|
|
3
5
|
export class InsertCodeSnippetElement extends HTMLElement {
|
|
6
|
+
#actionButton;
|
|
7
|
+
|
|
8
|
+
#codeBlock;
|
|
9
|
+
|
|
4
10
|
constructor(codeBlock) {
|
|
5
11
|
super();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
this.#actionButton = createButton();
|
|
13
|
+
|
|
14
|
+
// we handle two possible cases here:
|
|
15
|
+
// 1. we use constructor parameter if the element is created in Javscript and inserted in the document
|
|
16
|
+
// 2. we find the wrapping element containing code if the element is received from the server
|
|
17
|
+
this.#codeBlock = codeBlock ?? this.closest(`.${CODE_MARKDOWN_CLASS}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#handleClick = () => {
|
|
21
|
+
if (this.#codeBlock) {
|
|
22
|
+
this.#codeBlock.dispatchEvent(
|
|
23
|
+
new CustomEvent('insert-code-snippet', {
|
|
24
|
+
bubbles: true,
|
|
25
|
+
cancelable: true,
|
|
26
|
+
detail: {
|
|
27
|
+
code: this.#codeBlock.textContent.trim(),
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
connectedCallback() {
|
|
35
|
+
this.appendChild(this.#actionButton);
|
|
36
|
+
this.#actionButton.addEventListener('click', this.#handleClick);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
disconnectedCallback() {
|
|
40
|
+
this.#actionButton.removeEventListener('click', this.#handleClick);
|
|
16
41
|
}
|
|
17
42
|
}
|
|
@@ -429,6 +429,10 @@ export default {
|
|
|
429
429
|
}
|
|
430
430
|
},
|
|
431
431
|
onInsertCodeSnippet(e) {
|
|
432
|
+
/**
|
|
433
|
+
* Emit insert-code-snippet event that clients can use to interact with a suggested code.
|
|
434
|
+
* @param {*} event An event containing code string in the "detail.code" field.
|
|
435
|
+
*/
|
|
432
436
|
this.$emit('insert-code-snippet', e);
|
|
433
437
|
},
|
|
434
438
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { setStoryTimeout } from '../../../../utils/test_utils';
|
|
2
|
-
import { InsertCodeSnippetElement } from './components/duo_chat_message/insert_code_snippet_element';
|
|
3
2
|
import {
|
|
4
3
|
DOCUMENTATION_SOURCE_TYPES,
|
|
5
4
|
MESSAGE_MODEL_ROLES,
|
|
@@ -144,7 +143,6 @@ export const renderGFM = (el) => {
|
|
|
144
143
|
const codeBlock = el.querySelectorAll('.markdown-code-block');
|
|
145
144
|
codeBlock.forEach((block) => {
|
|
146
145
|
block?.classList.add('gl-markdown', 'gl-compact-markdown');
|
|
147
|
-
block?.appendChild(new InsertCodeSnippetElement(block));
|
|
148
146
|
});
|
|
149
147
|
};
|
|
150
148
|
|