@tuidom/elements 0.1.0 → 0.2.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/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @tuidom/elements
|
|
2
|
+
|
|
3
|
+
Widgets for [TUIDom](https://github.com/tuidom/tuidom): boxes, flex containers,
|
|
4
|
+
text, buttons, inputs, lists (virtualized), trees, menus, quick pick,
|
|
5
|
+
scrollbars, editor tabs, workbench shell, embedded-terminal view.
|
|
6
|
+
|
|
7
|
+
> ⚠️ Experimental — the API is unstable, deep imports expose internals on purpose.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @tuidom/core @tuidom/elements @tuidom/terminal-backend
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { TuiApplication } from "@tuidom/core/dom/tuiApplication";
|
|
15
|
+
import { BodyElement } from "@tuidom/elements/body/bodyElement";
|
|
16
|
+
import { BoxElement } from "@tuidom/elements/layout/boxElement";
|
|
17
|
+
import { NodeTerminalBackend } from "@tuidom/terminal-backend/nodeTerminalBackend";
|
|
18
|
+
|
|
19
|
+
const app = new TuiApplication(new NodeTerminalBackend());
|
|
20
|
+
const body = new BodyElement();
|
|
21
|
+
body.title = "hello";
|
|
22
|
+
body.setContent(new BoxElement());
|
|
23
|
+
app.root = body;
|
|
24
|
+
app.run();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Full guide (incl. an overview table of all elements):
|
|
28
|
+
<https://github.com/tuidom/tuidom/blob/main/GUIDE.md>
|
|
@@ -11,6 +11,8 @@ export declare class EditorTabItemElement extends TUIElement {
|
|
|
11
11
|
private hovered;
|
|
12
12
|
onActivate: (() => void) | null;
|
|
13
13
|
onClose: (() => void) | null;
|
|
14
|
+
/** Правый клик по вкладке — якорь в экранных координатах курсора. */
|
|
15
|
+
onContextMenu: ((screenX: number, screenY: number) => void) | null;
|
|
14
16
|
constructor(label: string, icon: string, iconColor: number, options?: {
|
|
15
17
|
modified?: boolean;
|
|
16
18
|
readOnly?: boolean;
|
|
@@ -18,6 +18,8 @@ export class EditorTabItemElement extends TUIElement {
|
|
|
18
18
|
hovered = false;
|
|
19
19
|
onActivate = null;
|
|
20
20
|
onClose = null;
|
|
21
|
+
/** Правый клик по вкладке — якорь в экранных координатах курсора. */
|
|
22
|
+
onContextMenu = null;
|
|
21
23
|
constructor(label, icon, iconColor, options) {
|
|
22
24
|
super();
|
|
23
25
|
this.label = label;
|
|
@@ -29,6 +31,12 @@ export class EditorTabItemElement extends TUIElement {
|
|
|
29
31
|
this.paddingRight = options?.paddingRight ?? 1;
|
|
30
32
|
this.addEventListener("click", (event) => {
|
|
31
33
|
const mouseEvent = event;
|
|
34
|
+
// Активируют и закрывают вкладку только левая и средняя кнопки: правый
|
|
35
|
+
// клик обязан лишь открыть контекстное меню, не трогая ни активную
|
|
36
|
+
// вкладку, ни крестик (VS Code так же). Гард — как у остальных
|
|
37
|
+
// виджетов пакета (treeViewElement, listViewElement, quickPickElement).
|
|
38
|
+
if (mouseEvent.button !== "left" && mouseEvent.button !== "middle")
|
|
39
|
+
return;
|
|
32
40
|
// Middle click closes the tab regardless of where it lands (VSCode behaviour).
|
|
33
41
|
if (mouseEvent.button === "middle") {
|
|
34
42
|
this.onClose?.();
|
|
@@ -42,6 +50,12 @@ export class EditorTabItemElement extends TUIElement {
|
|
|
42
50
|
this.onActivate?.();
|
|
43
51
|
}
|
|
44
52
|
});
|
|
53
|
+
// Ядро синтезирует "contextmenu" из правого клика (contextMenuEventSource);
|
|
54
|
+
// вкладка только сигналит наружу — меню собирает приложение.
|
|
55
|
+
this.addEventListener("contextmenu", (event) => {
|
|
56
|
+
const contextMenuEvent = event;
|
|
57
|
+
this.onContextMenu?.(contextMenuEvent.screenX, contextMenuEvent.screenY);
|
|
58
|
+
});
|
|
45
59
|
this.addEventListener("mouseenter", () => {
|
|
46
60
|
if (this.hovered)
|
|
47
61
|
return;
|
|
@@ -16,6 +16,12 @@ export declare class EditorTabStripElement extends TUIElement {
|
|
|
16
16
|
private activeIndexValue;
|
|
17
17
|
onTabActivate: ((index: number) => void) | null;
|
|
18
18
|
onTabClose: ((index: number) => void) | null;
|
|
19
|
+
/**
|
|
20
|
+
* Правый клик по вкладке: индекс вкладки под курсором и якорь меню в
|
|
21
|
+
* экранных координатах. Виджет только сигналит — меню собирает приложение
|
|
22
|
+
* (как {@link TreeViewElement.onContextMenu}).
|
|
23
|
+
*/
|
|
24
|
+
onTabContextMenu: ((index: number, screenX: number, screenY: number) => void) | null;
|
|
19
25
|
constructor();
|
|
20
26
|
get activeIndex(): number;
|
|
21
27
|
set activeIndex(value: number);
|
|
@@ -11,6 +11,12 @@ export class EditorTabStripElement extends TUIElement {
|
|
|
11
11
|
activeIndexValue = -1;
|
|
12
12
|
onTabActivate = null;
|
|
13
13
|
onTabClose = null;
|
|
14
|
+
/**
|
|
15
|
+
* Правый клик по вкладке: индекс вкладки под курсором и якорь меню в
|
|
16
|
+
* экранных координатах. Виджет только сигналит — меню собирает приложение
|
|
17
|
+
* (как {@link TreeViewElement.onContextMenu}).
|
|
18
|
+
*/
|
|
19
|
+
onTabContextMenu = null;
|
|
14
20
|
constructor() {
|
|
15
21
|
super();
|
|
16
22
|
this.hflex = new HFlexElement();
|
|
@@ -72,6 +78,7 @@ export class EditorTabStripElement extends TUIElement {
|
|
|
72
78
|
const index = i;
|
|
73
79
|
item.onActivate = () => this.onTabActivate?.(index);
|
|
74
80
|
item.onClose = () => this.onTabClose?.(index);
|
|
81
|
+
item.onContextMenu = (screenX, screenY) => this.onTabContextMenu?.(index, screenX, screenY);
|
|
75
82
|
}
|
|
76
83
|
newItems.push(item);
|
|
77
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuidom/elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Experimental terminal UI DOM — widgets: lists, trees, menus, inputs, quick pick. API is unstable.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"./*": "./dist/*.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tuidom/core": "0.
|
|
31
|
+
"@tuidom/core": "0.2.0"
|
|
32
32
|
}
|
|
33
33
|
}
|