-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import { type Workspace } from "@yamori/proto/yamori/workspace/v1/workspace_pb.js";
import { YamoriButton } from "../../components/button/button.ts";
import { wrapElement, YamoriElement } from "../../element.ts";
import css from "./workspace-list-entry.css?inline";
export class OpenEvent extends Event {
constructor(public readonly workspace: Workspace) {
super("open", {
bubbles: true,
cancelable: true,
composed: true,
});
}
}
export const YamoriWorkspaceListEntry = wrapElement({
tagName: "yamori-workspace-list-entry",
dependencies: [YamoriButton],
constructor: class extends YamoriElement {
#shadow: ShadowRoot;
#startMarker: Comment;
#endMarker: Comment;
#workspace: Workspace | null = null;
constructor() {
super();
this.#shadow = this.attachShadow({
mode: "open",
});
const style = document.createElement("style");
style.textContent = css;
this.#shadow.appendChild(style);
this.#startMarker = document.createComment("");
this.#shadow.appendChild(this.#startMarker);
this.#endMarker = document.createComment("");
this.#shadow.appendChild(this.#endMarker);
this.internals.role = "listitem";
}
override connectedCallback(): void {
super.connectedCallback();
this.#render();
}
#render = (): void => {
const range = document.createRange();
range.setStartAfter(this.#startMarker);
range.setEndBefore(this.#endMarker);
range.deleteContents();
const workspace = this.#workspace;
if (!workspace) {
this.setCustomState("nodata");
return;
}
this.removeCustomState("nodata");
const label = document.createElement("span");
label.textContent = "Workspace";
label.classList.add("label");
this.#shadow.insertBefore(label, this.#endMarker);
const displayName = document.createElement("span");
displayName.textContent = workspace.displayName;
displayName.classList.add("display-name");
this.#shadow.insertBefore(displayName, this.#endMarker);
const button = document.createElement(YamoriButton.tagName);
button.textContent = "開く";
this.#shadow.insertBefore(button, this.#endMarker);
button.addEventListener("click", (event) => {
event.preventDefault();
event.stopPropagation();
this.dispatchEvent(new OpenEvent(workspace));
});
};
setWorkspace(workspace: Workspace) {
this.#workspace = workspace;
this.#render();
}
},
});