@theia/collaboration 1.53.0-next.55 → 1.53.0-next.64
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 +33 -33
- package/lib/browser/collaboration-instance.js +15 -15
- package/package.json +7 -7
- package/src/browser/collaboration-color-service.ts +77 -77
- package/src/browser/collaboration-file-system-provider.ts +119 -119
- package/src/browser/collaboration-frontend-contribution.ts +327 -327
- package/src/browser/collaboration-frontend-module.ts +37 -37
- package/src/browser/collaboration-instance.ts +819 -819
- package/src/browser/collaboration-utils.ts +59 -59
- package/src/browser/collaboration-workspace-service.ts +69 -69
- package/src/browser/style/index.css +22 -22
- package/src/package.spec.ts +28 -28
package/README.md
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
<div align='center'>
|
|
2
|
-
|
|
3
|
-
<br />
|
|
4
|
-
|
|
5
|
-
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
-
|
|
7
|
-
<h2>ECLIPSE THEIA - COLLABORATION EXTENSION</h2>
|
|
8
|
-
|
|
9
|
-
<hr />
|
|
10
|
-
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
## Description
|
|
14
|
-
|
|
15
|
-
The `@theia/collaboration` extension features to enable collaboration between multiple peers using Theia.
|
|
16
|
-
This is built on top of the [Open Collaboration Tools](https://www.open-collab.tools/) ([GitHub](https://github.com/TypeFox/open-collaboration-tools)) project.
|
|
17
|
-
|
|
18
|
-
Note that the project is still in a beta phase and can be subject to unexpected breaking changes. This package is therefore in a beta phase as well.
|
|
19
|
-
|
|
20
|
-
## Additional Information
|
|
21
|
-
|
|
22
|
-
- [API documentation for `@theia/collaboration`](https://eclipse-theia.github.io/theia/docs/next/modules/collaboration.html)
|
|
23
|
-
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
24
|
-
- [Theia - Website](https://theia-ide.org/)
|
|
25
|
-
|
|
26
|
-
## License
|
|
27
|
-
|
|
28
|
-
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
29
|
-
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
30
|
-
|
|
31
|
-
## Trademark
|
|
32
|
-
"Theia" is a trademark of the Eclipse Foundation
|
|
33
|
-
https://www.eclipse.org/theia
|
|
1
|
+
<div align='center'>
|
|
2
|
+
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
+
|
|
7
|
+
<h2>ECLIPSE THEIA - COLLABORATION EXTENSION</h2>
|
|
8
|
+
|
|
9
|
+
<hr />
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
The `@theia/collaboration` extension features to enable collaboration between multiple peers using Theia.
|
|
16
|
+
This is built on top of the [Open Collaboration Tools](https://www.open-collab.tools/) ([GitHub](https://github.com/TypeFox/open-collaboration-tools)) project.
|
|
17
|
+
|
|
18
|
+
Note that the project is still in a beta phase and can be subject to unexpected breaking changes. This package is therefore in a beta phase as well.
|
|
19
|
+
|
|
20
|
+
## Additional Information
|
|
21
|
+
|
|
22
|
+
- [API documentation for `@theia/collaboration`](https://eclipse-theia.github.io/theia/docs/next/modules/collaboration.html)
|
|
23
|
+
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
24
|
+
- [Theia - Website](https://theia-ide.org/)
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
29
|
+
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
30
|
+
|
|
31
|
+
## Trademark
|
|
32
|
+
"Theia" is a trademark of the Eclipse Foundation
|
|
33
|
+
https://www.eclipse.org/theia
|
|
@@ -559,25 +559,25 @@ let CollaborationInstance = class CollaborationInstance {
|
|
|
559
559
|
const sheet = style.sheet;
|
|
560
560
|
const color = colors[this.colorIndex++ % colors.length];
|
|
561
561
|
const colorString = `rgb(${color.r}, ${color.g}, ${color.b})`;
|
|
562
|
-
sheet.insertRule(`
|
|
563
|
-
.${exports.COLLABORATION_SELECTION}-${peer.id} {
|
|
564
|
-
opacity: 0.2;
|
|
565
|
-
background: ${colorString};
|
|
566
|
-
}
|
|
562
|
+
sheet.insertRule(`
|
|
563
|
+
.${exports.COLLABORATION_SELECTION}-${peer.id} {
|
|
564
|
+
opacity: 0.2;
|
|
565
|
+
background: ${colorString};
|
|
566
|
+
}
|
|
567
567
|
`);
|
|
568
|
-
sheet.insertRule(`
|
|
569
|
-
.${exports.COLLABORATION_SELECTION_MARKER}-${peer.id} {
|
|
570
|
-
background: ${colorString};
|
|
571
|
-
border-color: ${colorString};
|
|
568
|
+
sheet.insertRule(`
|
|
569
|
+
.${exports.COLLABORATION_SELECTION_MARKER}-${peer.id} {
|
|
570
|
+
background: ${colorString};
|
|
571
|
+
border-color: ${colorString};
|
|
572
572
|
}`);
|
|
573
|
-
sheet.insertRule(`
|
|
574
|
-
.${exports.COLLABORATION_SELECTION_MARKER}-${peer.id}::after {
|
|
575
|
-
content: "${peer.name}";
|
|
576
|
-
background: ${colorString};
|
|
573
|
+
sheet.insertRule(`
|
|
574
|
+
.${exports.COLLABORATION_SELECTION_MARKER}-${peer.id}::after {
|
|
575
|
+
content: "${peer.name}";
|
|
576
|
+
background: ${colorString};
|
|
577
577
|
color: ${this.collaborationColorService.requiresDarkFont(color)
|
|
578
578
|
? this.collaborationColorService.dark
|
|
579
|
-
: this.collaborationColorService.light};
|
|
580
|
-
z-index: ${(100 + this.colorIndex).toFixed()}
|
|
579
|
+
: this.collaborationColorService.light};
|
|
580
|
+
z-index: ${(100 + this.colorIndex).toFixed()}
|
|
581
581
|
}`);
|
|
582
582
|
return core_1.Disposable.create(() => style.remove());
|
|
583
583
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/collaboration",
|
|
3
|
-
"version": "1.53.0-next.
|
|
3
|
+
"version": "1.53.0-next.64+23b351d26",
|
|
4
4
|
"description": "Theia - Collaboration Extension",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.53.0-next.
|
|
7
|
-
"@theia/editor": "1.53.0-next.
|
|
8
|
-
"@theia/filesystem": "1.53.0-next.
|
|
9
|
-
"@theia/monaco": "1.53.0-next.
|
|
6
|
+
"@theia/core": "1.53.0-next.64+23b351d26",
|
|
7
|
+
"@theia/editor": "1.53.0-next.64+23b351d26",
|
|
8
|
+
"@theia/filesystem": "1.53.0-next.64+23b351d26",
|
|
9
|
+
"@theia/monaco": "1.53.0-next.64+23b351d26",
|
|
10
10
|
"@theia/monaco-editor-core": "1.83.101",
|
|
11
|
-
"@theia/workspace": "1.53.0-next.
|
|
11
|
+
"@theia/workspace": "1.53.0-next.64+23b351d26",
|
|
12
12
|
"lib0": "^0.2.52",
|
|
13
13
|
"open-collaboration-protocol": "0.2.0",
|
|
14
14
|
"open-collaboration-yjs": "0.2.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"nyc": {
|
|
55
55
|
"extends": "../../configs/nyc.json"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "23b351d26346a2b5d6aca3ee81fba59c056132f7"
|
|
58
58
|
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
|
|
19
|
-
export interface CollaborationColor {
|
|
20
|
-
r: number;
|
|
21
|
-
g: number;
|
|
22
|
-
b: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export namespace CollaborationColor {
|
|
26
|
-
export function fromString(code: string): CollaborationColor {
|
|
27
|
-
if (code.startsWith('#')) {
|
|
28
|
-
code = code.substring(1);
|
|
29
|
-
}
|
|
30
|
-
const r = parseInt(code.substring(0, 2), 16);
|
|
31
|
-
const g = parseInt(code.substring(2, 4), 16);
|
|
32
|
-
const b = parseInt(code.substring(4, 6), 16);
|
|
33
|
-
return { r, g, b };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const Gold = fromString('#FFD700');
|
|
37
|
-
export const Tomato = fromString('#FF6347');
|
|
38
|
-
export const Aquamarine = fromString('#7FFFD4');
|
|
39
|
-
export const Beige = fromString('#F5F5DC');
|
|
40
|
-
export const Coral = fromString('#FF7F50');
|
|
41
|
-
export const DarkOrange = fromString('#FF8C00');
|
|
42
|
-
export const VioletRed = fromString('#C71585');
|
|
43
|
-
export const DodgerBlue = fromString('#1E90FF');
|
|
44
|
-
export const Chocolate = fromString('#D2691E');
|
|
45
|
-
export const LightGreen = fromString('#90EE90');
|
|
46
|
-
export const MediumOrchid = fromString('#BA55D3');
|
|
47
|
-
export const Orange = fromString('#FFA500');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@injectable()
|
|
51
|
-
export class CollaborationColorService {
|
|
52
|
-
|
|
53
|
-
light = 'white';
|
|
54
|
-
dark = 'black';
|
|
55
|
-
|
|
56
|
-
getColors(): CollaborationColor[] {
|
|
57
|
-
return [
|
|
58
|
-
CollaborationColor.Gold,
|
|
59
|
-
CollaborationColor.Aquamarine,
|
|
60
|
-
CollaborationColor.Tomato,
|
|
61
|
-
CollaborationColor.MediumOrchid,
|
|
62
|
-
CollaborationColor.LightGreen,
|
|
63
|
-
CollaborationColor.Orange,
|
|
64
|
-
CollaborationColor.Beige,
|
|
65
|
-
CollaborationColor.Chocolate,
|
|
66
|
-
CollaborationColor.VioletRed,
|
|
67
|
-
CollaborationColor.Coral,
|
|
68
|
-
CollaborationColor.DodgerBlue,
|
|
69
|
-
CollaborationColor.DarkOrange
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
requiresDarkFont(color: CollaborationColor): boolean {
|
|
74
|
-
// From https://stackoverflow.com/a/3943023
|
|
75
|
-
return ((color.r * 0.299) + (color.g * 0.587) + (color.b * 0.114)) > 186;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
|
|
19
|
+
export interface CollaborationColor {
|
|
20
|
+
r: number;
|
|
21
|
+
g: number;
|
|
22
|
+
b: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export namespace CollaborationColor {
|
|
26
|
+
export function fromString(code: string): CollaborationColor {
|
|
27
|
+
if (code.startsWith('#')) {
|
|
28
|
+
code = code.substring(1);
|
|
29
|
+
}
|
|
30
|
+
const r = parseInt(code.substring(0, 2), 16);
|
|
31
|
+
const g = parseInt(code.substring(2, 4), 16);
|
|
32
|
+
const b = parseInt(code.substring(4, 6), 16);
|
|
33
|
+
return { r, g, b };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const Gold = fromString('#FFD700');
|
|
37
|
+
export const Tomato = fromString('#FF6347');
|
|
38
|
+
export const Aquamarine = fromString('#7FFFD4');
|
|
39
|
+
export const Beige = fromString('#F5F5DC');
|
|
40
|
+
export const Coral = fromString('#FF7F50');
|
|
41
|
+
export const DarkOrange = fromString('#FF8C00');
|
|
42
|
+
export const VioletRed = fromString('#C71585');
|
|
43
|
+
export const DodgerBlue = fromString('#1E90FF');
|
|
44
|
+
export const Chocolate = fromString('#D2691E');
|
|
45
|
+
export const LightGreen = fromString('#90EE90');
|
|
46
|
+
export const MediumOrchid = fromString('#BA55D3');
|
|
47
|
+
export const Orange = fromString('#FFA500');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@injectable()
|
|
51
|
+
export class CollaborationColorService {
|
|
52
|
+
|
|
53
|
+
light = 'white';
|
|
54
|
+
dark = 'black';
|
|
55
|
+
|
|
56
|
+
getColors(): CollaborationColor[] {
|
|
57
|
+
return [
|
|
58
|
+
CollaborationColor.Gold,
|
|
59
|
+
CollaborationColor.Aquamarine,
|
|
60
|
+
CollaborationColor.Tomato,
|
|
61
|
+
CollaborationColor.MediumOrchid,
|
|
62
|
+
CollaborationColor.LightGreen,
|
|
63
|
+
CollaborationColor.Orange,
|
|
64
|
+
CollaborationColor.Beige,
|
|
65
|
+
CollaborationColor.Chocolate,
|
|
66
|
+
CollaborationColor.VioletRed,
|
|
67
|
+
CollaborationColor.Coral,
|
|
68
|
+
CollaborationColor.DodgerBlue,
|
|
69
|
+
CollaborationColor.DarkOrange
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
requiresDarkFont(color: CollaborationColor): boolean {
|
|
74
|
+
// From https://stackoverflow.com/a/3943023
|
|
75
|
+
return ((color.r * 0.299) + (color.g * 0.587) + (color.b * 0.114)) > 186;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as Y from 'yjs';
|
|
18
|
-
import { Disposable, Emitter, Event, URI } from '@theia/core';
|
|
19
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
20
|
-
import {
|
|
21
|
-
FileChange, FileDeleteOptions,
|
|
22
|
-
FileOverwriteOptions, FileSystemProviderCapabilities, FileType, Stat, WatchOptions, FileSystemProviderWithFileReadWriteCapability, FileWriteOptions
|
|
23
|
-
} from '@theia/filesystem/lib/common/files';
|
|
24
|
-
import { ProtocolBroadcastConnection, Workspace, Peer } from 'open-collaboration-protocol';
|
|
25
|
-
|
|
26
|
-
export namespace CollaborationURI {
|
|
27
|
-
|
|
28
|
-
export const scheme = 'collaboration';
|
|
29
|
-
|
|
30
|
-
export function create(workspace: Workspace, path?: string): URI {
|
|
31
|
-
return new URI(`${scheme}:///${workspace.name}${path ? '/' + path : ''}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@injectable()
|
|
36
|
-
export class CollaborationFileSystemProvider implements FileSystemProviderWithFileReadWriteCapability {
|
|
37
|
-
|
|
38
|
-
capabilities = FileSystemProviderCapabilities.FileReadWrite;
|
|
39
|
-
|
|
40
|
-
protected _readonly: boolean;
|
|
41
|
-
|
|
42
|
-
get readonly(): boolean {
|
|
43
|
-
return this._readonly;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
set readonly(value: boolean) {
|
|
47
|
-
if (this._readonly !== value) {
|
|
48
|
-
this._readonly = value;
|
|
49
|
-
if (value) {
|
|
50
|
-
this.capabilities |= FileSystemProviderCapabilities.Readonly;
|
|
51
|
-
} else {
|
|
52
|
-
this.capabilities &= ~FileSystemProviderCapabilities.Readonly;
|
|
53
|
-
}
|
|
54
|
-
this.onDidChangeCapabilitiesEmitter.fire();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
constructor(readonly connection: ProtocolBroadcastConnection, readonly host: Peer, readonly yjs: Y.Doc) {
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected encoder = new TextEncoder();
|
|
62
|
-
protected decoder = new TextDecoder();
|
|
63
|
-
protected onDidChangeCapabilitiesEmitter = new Emitter<void>();
|
|
64
|
-
protected onDidChangeFileEmitter = new Emitter<readonly FileChange[]>();
|
|
65
|
-
protected onFileWatchErrorEmitter = new Emitter<void>();
|
|
66
|
-
|
|
67
|
-
get onDidChangeCapabilities(): Event<void> {
|
|
68
|
-
return this.onDidChangeCapabilitiesEmitter.event;
|
|
69
|
-
}
|
|
70
|
-
get onDidChangeFile(): Event<readonly FileChange[]> {
|
|
71
|
-
return this.onDidChangeFileEmitter.event;
|
|
72
|
-
}
|
|
73
|
-
get onFileWatchError(): Event<void> {
|
|
74
|
-
return this.onFileWatchErrorEmitter.event;
|
|
75
|
-
}
|
|
76
|
-
async readFile(resource: URI): Promise<Uint8Array> {
|
|
77
|
-
const path = this.getHostPath(resource);
|
|
78
|
-
if (this.yjs.share.has(path)) {
|
|
79
|
-
const stringValue = this.yjs.getText(path);
|
|
80
|
-
return this.encoder.encode(stringValue.toString());
|
|
81
|
-
} else {
|
|
82
|
-
const data = await this.connection.fs.readFile(this.host.id, path);
|
|
83
|
-
return data.content;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> {
|
|
87
|
-
const path = this.getHostPath(resource);
|
|
88
|
-
await this.connection.fs.writeFile(this.host.id, path, { content });
|
|
89
|
-
}
|
|
90
|
-
watch(resource: URI, opts: WatchOptions): Disposable {
|
|
91
|
-
return Disposable.NULL;
|
|
92
|
-
}
|
|
93
|
-
stat(resource: URI): Promise<Stat> {
|
|
94
|
-
return this.connection.fs.stat(this.host.id, this.getHostPath(resource));
|
|
95
|
-
}
|
|
96
|
-
mkdir(resource: URI): Promise<void> {
|
|
97
|
-
return this.connection.fs.mkdir(this.host.id, this.getHostPath(resource));
|
|
98
|
-
}
|
|
99
|
-
async readdir(resource: URI): Promise<[string, FileType][]> {
|
|
100
|
-
const record = await this.connection.fs.readdir(this.host.id, this.getHostPath(resource));
|
|
101
|
-
return Object.entries(record);
|
|
102
|
-
}
|
|
103
|
-
delete(resource: URI, opts: FileDeleteOptions): Promise<void> {
|
|
104
|
-
return this.connection.fs.delete(this.host.id, this.getHostPath(resource));
|
|
105
|
-
}
|
|
106
|
-
rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> {
|
|
107
|
-
return this.connection.fs.rename(this.host.id, this.getHostPath(from), this.getHostPath(to));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
protected getHostPath(uri: URI): string {
|
|
111
|
-
const path = uri.path.toString().substring(1).split('/');
|
|
112
|
-
return path.slice(1).join('/');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
triggerEvent(changes: FileChange[]): void {
|
|
116
|
-
this.onDidChangeFileEmitter.fire(changes);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as Y from 'yjs';
|
|
18
|
+
import { Disposable, Emitter, Event, URI } from '@theia/core';
|
|
19
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import {
|
|
21
|
+
FileChange, FileDeleteOptions,
|
|
22
|
+
FileOverwriteOptions, FileSystemProviderCapabilities, FileType, Stat, WatchOptions, FileSystemProviderWithFileReadWriteCapability, FileWriteOptions
|
|
23
|
+
} from '@theia/filesystem/lib/common/files';
|
|
24
|
+
import { ProtocolBroadcastConnection, Workspace, Peer } from 'open-collaboration-protocol';
|
|
25
|
+
|
|
26
|
+
export namespace CollaborationURI {
|
|
27
|
+
|
|
28
|
+
export const scheme = 'collaboration';
|
|
29
|
+
|
|
30
|
+
export function create(workspace: Workspace, path?: string): URI {
|
|
31
|
+
return new URI(`${scheme}:///${workspace.name}${path ? '/' + path : ''}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@injectable()
|
|
36
|
+
export class CollaborationFileSystemProvider implements FileSystemProviderWithFileReadWriteCapability {
|
|
37
|
+
|
|
38
|
+
capabilities = FileSystemProviderCapabilities.FileReadWrite;
|
|
39
|
+
|
|
40
|
+
protected _readonly: boolean;
|
|
41
|
+
|
|
42
|
+
get readonly(): boolean {
|
|
43
|
+
return this._readonly;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set readonly(value: boolean) {
|
|
47
|
+
if (this._readonly !== value) {
|
|
48
|
+
this._readonly = value;
|
|
49
|
+
if (value) {
|
|
50
|
+
this.capabilities |= FileSystemProviderCapabilities.Readonly;
|
|
51
|
+
} else {
|
|
52
|
+
this.capabilities &= ~FileSystemProviderCapabilities.Readonly;
|
|
53
|
+
}
|
|
54
|
+
this.onDidChangeCapabilitiesEmitter.fire();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
constructor(readonly connection: ProtocolBroadcastConnection, readonly host: Peer, readonly yjs: Y.Doc) {
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected encoder = new TextEncoder();
|
|
62
|
+
protected decoder = new TextDecoder();
|
|
63
|
+
protected onDidChangeCapabilitiesEmitter = new Emitter<void>();
|
|
64
|
+
protected onDidChangeFileEmitter = new Emitter<readonly FileChange[]>();
|
|
65
|
+
protected onFileWatchErrorEmitter = new Emitter<void>();
|
|
66
|
+
|
|
67
|
+
get onDidChangeCapabilities(): Event<void> {
|
|
68
|
+
return this.onDidChangeCapabilitiesEmitter.event;
|
|
69
|
+
}
|
|
70
|
+
get onDidChangeFile(): Event<readonly FileChange[]> {
|
|
71
|
+
return this.onDidChangeFileEmitter.event;
|
|
72
|
+
}
|
|
73
|
+
get onFileWatchError(): Event<void> {
|
|
74
|
+
return this.onFileWatchErrorEmitter.event;
|
|
75
|
+
}
|
|
76
|
+
async readFile(resource: URI): Promise<Uint8Array> {
|
|
77
|
+
const path = this.getHostPath(resource);
|
|
78
|
+
if (this.yjs.share.has(path)) {
|
|
79
|
+
const stringValue = this.yjs.getText(path);
|
|
80
|
+
return this.encoder.encode(stringValue.toString());
|
|
81
|
+
} else {
|
|
82
|
+
const data = await this.connection.fs.readFile(this.host.id, path);
|
|
83
|
+
return data.content;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> {
|
|
87
|
+
const path = this.getHostPath(resource);
|
|
88
|
+
await this.connection.fs.writeFile(this.host.id, path, { content });
|
|
89
|
+
}
|
|
90
|
+
watch(resource: URI, opts: WatchOptions): Disposable {
|
|
91
|
+
return Disposable.NULL;
|
|
92
|
+
}
|
|
93
|
+
stat(resource: URI): Promise<Stat> {
|
|
94
|
+
return this.connection.fs.stat(this.host.id, this.getHostPath(resource));
|
|
95
|
+
}
|
|
96
|
+
mkdir(resource: URI): Promise<void> {
|
|
97
|
+
return this.connection.fs.mkdir(this.host.id, this.getHostPath(resource));
|
|
98
|
+
}
|
|
99
|
+
async readdir(resource: URI): Promise<[string, FileType][]> {
|
|
100
|
+
const record = await this.connection.fs.readdir(this.host.id, this.getHostPath(resource));
|
|
101
|
+
return Object.entries(record);
|
|
102
|
+
}
|
|
103
|
+
delete(resource: URI, opts: FileDeleteOptions): Promise<void> {
|
|
104
|
+
return this.connection.fs.delete(this.host.id, this.getHostPath(resource));
|
|
105
|
+
}
|
|
106
|
+
rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> {
|
|
107
|
+
return this.connection.fs.rename(this.host.id, this.getHostPath(from), this.getHostPath(to));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected getHostPath(uri: URI): string {
|
|
111
|
+
const path = uri.path.toString().substring(1).split('/');
|
|
112
|
+
return path.slice(1).join('/');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
triggerEvent(changes: FileChange[]): void {
|
|
116
|
+
this.onDidChangeFileEmitter.fire(changes);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|