@vscode/web-editors 0.0.2-15 → 0.0.2-150

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.
@@ -0,0 +1,22 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { a as IDisposable, r as SyncedTextDocument } from "./chunks/syncedTextDocument-BIWK0LCP.js";
6
+ import * as vscode from "vscode";
7
+ //#region src/vscode/vsCodeTextDocument.d.ts
8
+ /**
9
+ * A {@link SyncedTextDocument} for a VS Code text document, to keep it in
10
+ * sync with a web editor through a `TextDocumentSync`.
11
+ *
12
+ * Writes go through `vscode.workspace.applyEdit`. VS Code rejects them if the
13
+ * document changed before they apply, and converts inserted line breaks to
14
+ * the document's line ending ({@link vscode.TextDocument.eol}); editors that
15
+ * insert that line ending themselves avoid the extra round trip.
16
+ */
17
+ declare function vsCodeTextDocument(document: vscode.TextDocument): SyncedTextDocument & IDisposable;
18
+ /** The line break VS Code inserts for `document`: what editors should insert to avoid conversions. */
19
+ declare function vsCodeLineBreak(document: vscode.TextDocument): "\n" | "\r\n";
20
+ //#endregion
21
+ export { vsCodeLineBreak, vsCodeTextDocument };
22
+ //# sourceMappingURL=vscode.d.ts.map
package/dist/vscode.js ADDED
@@ -0,0 +1,51 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { t as Emitter } from "./chunks/event-BrSLCUGr.js";
6
+ import * as vscode from "vscode";
7
+ //#region src/vscode/vsCodeTextDocument.ts
8
+ /**
9
+ * A {@link SyncedTextDocument} for a VS Code text document, to keep it in
10
+ * sync with a web editor through a `TextDocumentSync`.
11
+ *
12
+ * Writes go through `vscode.workspace.applyEdit`. VS Code rejects them if the
13
+ * document changed before they apply, and converts inserted line breaks to
14
+ * the document's line ending ({@link vscode.TextDocument.eol}); editors that
15
+ * insert that line ending themselves avoid the extra round trip.
16
+ */
17
+ function vsCodeTextDocument(document) {
18
+ const onDidChangeText = new Emitter();
19
+ const subscription = vscode.workspace.onDidChangeTextDocument((event) => {
20
+ if (event.document === document && event.contentChanges.length > 0) onDidChangeText.fire({ edits: event.contentChanges.map((c) => ({
21
+ offset: c.rangeOffset,
22
+ length: c.rangeLength,
23
+ newText: c.text
24
+ })) });
25
+ });
26
+ return {
27
+ get version() {
28
+ return document.version;
29
+ },
30
+ getText: () => document.getText(),
31
+ applyEdits: async (version, edits) => {
32
+ if (document.version !== version) return false;
33
+ const edit = new vscode.WorkspaceEdit();
34
+ for (const { offset, length, newText } of edits) edit.replace(document.uri, new vscode.Range(document.positionAt(offset), document.positionAt(offset + length)), newText);
35
+ return vscode.workspace.applyEdit(edit);
36
+ },
37
+ onDidChangeText: onDidChangeText.event,
38
+ dispose: () => {
39
+ subscription.dispose();
40
+ onDidChangeText.dispose();
41
+ }
42
+ };
43
+ }
44
+ /** The line break VS Code inserts for `document`: what editors should insert to avoid conversions. */
45
+ function vsCodeLineBreak(document) {
46
+ return document.eol === vscode.EndOfLine.CRLF ? "\r\n" : "\n";
47
+ }
48
+ //#endregion
49
+ export { vsCodeLineBreak, vsCodeTextDocument };
50
+
51
+ //# sourceMappingURL=vscode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vscode.js","names":[],"sources":["../src/vscode/vsCodeTextDocument.ts"],"sourcesContent":["import * as vscode from \"vscode\";\nimport type { DocumentTextChange, DocumentTextEdit, SyncedTextDocument } from \"../documentSync/syncedTextDocument\";\nimport { Emitter, type IDisposable } from \"../utils/event\";\n\n/**\n * A {@link SyncedTextDocument} for a VS Code text document, to keep it in\n * sync with a web editor through a `TextDocumentSync`.\n *\n * Writes go through `vscode.workspace.applyEdit`. VS Code rejects them if the\n * document changed before they apply, and converts inserted line breaks to\n * the document's line ending ({@link vscode.TextDocument.eol}); editors that\n * insert that line ending themselves avoid the extra round trip.\n */\nexport function vsCodeTextDocument(document: vscode.TextDocument): SyncedTextDocument & IDisposable {\n const onDidChangeText = new Emitter<DocumentTextChange>();\n const subscription = vscode.workspace.onDidChangeTextDocument(event => {\n // Saving fires an event without content changes when the dirty state flips.\n if (event.document === document && event.contentChanges.length > 0) {\n // All ranges of one event refer to the text before it (VS Code orders them from the end).\n onDidChangeText.fire({ edits: event.contentChanges.map(c => ({ offset: c.rangeOffset, length: c.rangeLength, newText: c.text })) });\n }\n });\n return {\n get version() {\n return document.version;\n },\n getText: () => document.getText(),\n applyEdits: async (version: number, edits: readonly DocumentTextEdit[]) => {\n if (document.version !== version) {\n return false;\n }\n const edit = new vscode.WorkspaceEdit();\n for (const { offset, length, newText } of edits) {\n edit.replace(document.uri, new vscode.Range(document.positionAt(offset), document.positionAt(offset + length)), newText);\n }\n // The extension host sends the edit with the document's current version; VS Code rejects it if the document changes first.\n return vscode.workspace.applyEdit(edit);\n },\n onDidChangeText: onDidChangeText.event,\n dispose: () => {\n subscription.dispose();\n onDidChangeText.dispose();\n },\n };\n}\n\n/** The line break VS Code inserts for `document`: what editors should insert to avoid conversions. */\nexport function vsCodeLineBreak(document: vscode.TextDocument): \"\\n\" | \"\\r\\n\" {\n return document.eol === vscode.EndOfLine.CRLF ? \"\\r\\n\" : \"\\n\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,UAAiE;CAChG,MAAM,kBAAkB,IAAI,QAA4B;CACxD,MAAM,eAAe,OAAO,UAAU,yBAAwB,UAAS;EAEnE,IAAI,MAAM,aAAa,YAAY,MAAM,eAAe,SAAS,GAE7D,gBAAgB,KAAK,EAAE,OAAO,MAAM,eAAe,KAAI,OAAM;GAAE,QAAQ,EAAE;GAAa,QAAQ,EAAE;GAAa,SAAS,EAAE;EAAK,EAAE,EAAE,CAAC;CAE1I,CAAC;CACD,OAAO;EACH,IAAI,UAAU;GACV,OAAO,SAAS;EACpB;EACA,eAAe,SAAS,QAAQ;EAChC,YAAY,OAAO,SAAiB,UAAuC;GACvE,IAAI,SAAS,YAAY,SACrB,OAAO;GAEX,MAAM,OAAO,IAAI,OAAO,cAAc;GACtC,KAAK,MAAM,EAAE,QAAQ,QAAQ,aAAa,OACtC,KAAK,QAAQ,SAAS,KAAK,IAAI,OAAO,MAAM,SAAS,WAAW,MAAM,GAAG,SAAS,WAAW,SAAS,MAAM,CAAC,GAAG,OAAO;GAG3H,OAAO,OAAO,UAAU,UAAU,IAAI;EAC1C;EACA,iBAAiB,gBAAgB;EACjC,eAAe;GACX,aAAa,QAAQ;GACrB,gBAAgB,QAAQ;EAC5B;CACJ;AACJ;;AAGA,SAAgB,gBAAgB,UAA8C;CAC1E,OAAO,SAAS,QAAQ,OAAO,UAAU,OAAO,SAAS;AAC7D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vscode/web-editors",
3
- "version": "0.0.2-15",
3
+ "version": "0.0.2-150",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,20 +23,28 @@
23
23
  "types": "./dist/index.d.ts",
24
24
  "default": "./dist/index.js"
25
25
  },
26
+ "./vscode": {
27
+ "types": "./dist/vscode.d.ts",
28
+ "default": "./dist/vscode.js"
29
+ },
26
30
  "./standalone-app-adapter.js": "./dist/standalone-app-adapter.js"
27
31
  },
28
32
  "scripts": {
33
+ "typecheck": "tsc -p . --noEmit",
29
34
  "build": "tsdown",
30
- "dev": "tsdown --watch"
35
+ "dev": "tsdown --watch",
36
+ "test": "vitest --run"
31
37
  },
32
38
  "dependencies": {
33
39
  "@vscode/hubrpc": "next"
34
40
  },
35
41
  "devDependencies": {
42
+ "@types/vscode": "^1.100.0",
36
43
  "tsdown": "^0.22.3",
37
44
  "tslib": "^2.8.1",
38
45
  "typescript": "^6.0.3",
46
+ "vitest": "^4.1.0",
39
47
  "zod": "^4.4.3"
40
48
  },
41
- "gitHead": "a2e9b00059d3373e828b5d1e6515e82c4629af46"
49
+ "gitHead": "cb44454b946b0c0d01ea96e51f2b05850ea7efc9"
42
50
  }