@vscode/web-editors 0.0.2-40 → 0.0.2-42
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/dist/index.d.ts +28 -1
- package/dist/index.js +57 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2148,6 +2148,7 @@ declare const zHostCapabilities: ZodObject<{
|
|
|
2148
2148
|
supportsContentEdits: ZodOptional<ZodBoolean>;
|
|
2149
2149
|
supportsOptions: ZodOptional<ZodBoolean>;
|
|
2150
2150
|
supportsForceUpdate: ZodOptional<ZodBoolean>;
|
|
2151
|
+
supportsHostTransport: ZodOptional<ZodBoolean>;
|
|
2151
2152
|
}, $strip>;
|
|
2152
2153
|
declare const zTextEdit: ZodObject<{
|
|
2153
2154
|
offset: ZodNumber;
|
|
@@ -2183,6 +2184,8 @@ type WebEditorUpdate = output<typeof zWebEditorUpdate>;
|
|
|
2183
2184
|
type ContentType = "text" | "json";
|
|
2184
2185
|
declare const webEditorHostInterface: any;
|
|
2185
2186
|
declare const webEditorInterface: any;
|
|
2187
|
+
declare const webEditorHostTransportInterface: any;
|
|
2188
|
+
declare const webEditorClientTransportInterface: any;
|
|
2186
2189
|
declare const zEmbeddedAppDescriptor: ZodObject<{
|
|
2187
2190
|
handleId: ZodString;
|
|
2188
2191
|
appId: ZodString;
|
|
@@ -2205,6 +2208,8 @@ declare const vscodeAppEmbeddingEventsInterface: any;
|
|
|
2205
2208
|
type WebEditorHostProxy = InterfaceClient<typeof webEditorHostInterface>;
|
|
2206
2209
|
/** Typed proxy used by the host to invoke editor methods. */
|
|
2207
2210
|
type WebEditorProxy = InterfaceClient<typeof webEditorInterface>;
|
|
2211
|
+
type WebEditorHostTransportProxy = InterfaceClient<typeof webEditorHostTransportInterface>;
|
|
2212
|
+
type WebEditorClientTransportProxy = InterfaceClient<typeof webEditorClientTransportInterface>;
|
|
2208
2213
|
/** Typed proxy used by an app to invoke `vscode-app-host` methods. */
|
|
2209
2214
|
type VsCodeAppHostProxy = InterfaceClient<typeof vscodeAppHostInterface>;
|
|
2210
2215
|
type VsCodeAppEmbeddingEventsProxy = InterfaceClient<typeof vscodeAppEmbeddingEventsInterface>;
|
|
@@ -2280,6 +2285,16 @@ interface IDisposable {
|
|
|
2280
2285
|
type EventListener<T> = (event: T) => void;
|
|
2281
2286
|
type Event<T> = (listener: EventListener<T>) => IDisposable;
|
|
2282
2287
|
//#endregion
|
|
2288
|
+
//#region src/hostTransport.d.ts
|
|
2289
|
+
/**
|
|
2290
|
+
* Optional message transport between a web editor and its host.
|
|
2291
|
+
*/
|
|
2292
|
+
interface HostTransport {
|
|
2293
|
+
readonly onMessage: Event<JsonValue>;
|
|
2294
|
+
/** Sends a notification to the host. */
|
|
2295
|
+
sendMessage(message: JsonValue): void;
|
|
2296
|
+
}
|
|
2297
|
+
//#endregion
|
|
2283
2298
|
//#region src/host/WebEditorHost.d.ts
|
|
2284
2299
|
interface WebEditorHostOptions {
|
|
2285
2300
|
/**
|
|
@@ -2302,6 +2317,8 @@ interface WebEditorHostOptions {
|
|
|
2302
2317
|
jsonFormat?: JsonFormatOptions;
|
|
2303
2318
|
/** Host capabilities advertised on `initialized`. */
|
|
2304
2319
|
capabilities?: HostCapabilities;
|
|
2320
|
+
/** Optional message transport to expose to the editor. */
|
|
2321
|
+
hostTransport?: HostTransport;
|
|
2305
2322
|
/** Called when the editor sends malformed input. Defaults to `console.error`. */
|
|
2306
2323
|
onError?: (message: string, detail?: unknown) => void;
|
|
2307
2324
|
}
|
|
@@ -2315,16 +2332,19 @@ interface WebEditorHostOptions {
|
|
|
2315
2332
|
declare class WebEditorHost implements IDisposable {
|
|
2316
2333
|
private readonly _connection;
|
|
2317
2334
|
private readonly _editor;
|
|
2335
|
+
private readonly _clientTransport;
|
|
2318
2336
|
private readonly _contentType;
|
|
2319
2337
|
private readonly _jsonFormat;
|
|
2320
2338
|
private readonly _onError;
|
|
2321
2339
|
private readonly _capabilities;
|
|
2340
|
+
private readonly _hostTransportSubscription;
|
|
2322
2341
|
private _text;
|
|
2323
2342
|
private _readOnly;
|
|
2324
2343
|
private _serverRevision;
|
|
2325
2344
|
private _acknowledgedClientRevision;
|
|
2326
2345
|
private _editorInitialized;
|
|
2327
2346
|
private _editorCapabilities;
|
|
2347
|
+
private readonly _pendingHostTransportMessages;
|
|
2328
2348
|
private readonly _onDidChangeText;
|
|
2329
2349
|
readonly onDidChangeText: Event<{
|
|
2330
2350
|
text: string;
|
|
@@ -2463,11 +2483,15 @@ interface WebEditorClientState {
|
|
|
2463
2483
|
declare class WebEditorClient implements IDisposable {
|
|
2464
2484
|
private readonly _connection;
|
|
2465
2485
|
private readonly _host;
|
|
2486
|
+
private readonly _hostTransportProxy;
|
|
2466
2487
|
private readonly _onError;
|
|
2488
|
+
private _hostTransport;
|
|
2467
2489
|
private _content;
|
|
2468
2490
|
private _readOnly;
|
|
2469
2491
|
private _options;
|
|
2470
2492
|
private _hostCapabilities;
|
|
2493
|
+
private readonly _pendingHostTransportMessages;
|
|
2494
|
+
private _hostTransportActivated;
|
|
2471
2495
|
private _clientRevision;
|
|
2472
2496
|
private _basedOnServerRevision;
|
|
2473
2497
|
/** Number of un-acked local revisions. While > 0 the editor has pending edits. */
|
|
@@ -2490,6 +2514,7 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2490
2514
|
readonly onDidChangeOptions: Event<{
|
|
2491
2515
|
options: JsonValue;
|
|
2492
2516
|
}>;
|
|
2517
|
+
private readonly _onDidReceiveHostMessage;
|
|
2493
2518
|
/** Resolves once the host has acknowledged `initialized`. */
|
|
2494
2519
|
readonly onDidConnect: Promise<{
|
|
2495
2520
|
capabilities: HostCapabilities | undefined;
|
|
@@ -2502,6 +2527,8 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2502
2527
|
* second one.
|
|
2503
2528
|
*/
|
|
2504
2529
|
get connection(): HubRpcConnection;
|
|
2530
|
+
/** Optional notification transport supplied by the web editor host. */
|
|
2531
|
+
get hostTransport(): HostTransport | undefined;
|
|
2505
2532
|
getContent(): JsonValue;
|
|
2506
2533
|
getReadOnly(): boolean;
|
|
2507
2534
|
getOptions(): JsonValue;
|
|
@@ -2656,5 +2683,5 @@ declare class VsCodeAppHostClient {
|
|
|
2656
2683
|
}): Promise<EditorAssociationResult>;
|
|
2657
2684
|
}
|
|
2658
2685
|
//#endregion
|
|
2659
|
-
export { AppContext, type ConnectionInput, ContentEdit, ContentType, EditorAssociationResult, EditorCapabilities, EditorRegistrationStatus, EditorScope, EmbeddedAppAccessOptions, EmbeddedAppDescriptor, EmbeddedAppHandle, EmbeddingContext, type Event, HostCapabilities, type IDisposable, JsonFormatOptions, JsonValue, type MessageEndpoint, type MessageLikeEvent, ScopeRegistration, TextEdit, VsCodeAppEmbeddingEventsProxy, VsCodeAppHostClient, VsCodeAppHostClientOptions, VsCodeAppHostProxy, WebEditorClient, WebEditorClientOptions, WebEditorClientState, WebEditorHost, WebEditorHostOptions, WebEditorHostProxy, WebEditorProxy, WebEditorUpdate, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorHostInterface, webEditorInterface };
|
|
2686
|
+
export { AppContext, type ConnectionInput, ContentEdit, ContentType, EditorAssociationResult, EditorCapabilities, EditorRegistrationStatus, EditorScope, EmbeddedAppAccessOptions, EmbeddedAppDescriptor, EmbeddedAppHandle, EmbeddingContext, type Event, HostCapabilities, HostTransport, type IDisposable, JsonFormatOptions, JsonValue, type MessageEndpoint, type MessageLikeEvent, ScopeRegistration, TextEdit, VsCodeAppEmbeddingEventsProxy, VsCodeAppHostClient, VsCodeAppHostClientOptions, VsCodeAppHostProxy, WebEditorClient, WebEditorClientOptions, WebEditorClientState, WebEditorClientTransportProxy, WebEditorHost, WebEditorHostOptions, WebEditorHostProxy, WebEditorHostTransportProxy, WebEditorProxy, WebEditorUpdate, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface };
|
|
2660
2687
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -4125,7 +4125,8 @@ const zEditorCapabilities = object({
|
|
|
4125
4125
|
const zHostCapabilities = object({
|
|
4126
4126
|
supportsContentEdits: boolean().optional(),
|
|
4127
4127
|
supportsOptions: boolean().optional(),
|
|
4128
|
-
supportsForceUpdate: boolean().optional()
|
|
4128
|
+
supportsForceUpdate: boolean().optional(),
|
|
4129
|
+
supportsHostTransport: boolean().optional()
|
|
4129
4130
|
});
|
|
4130
4131
|
const zTextEdit = object({
|
|
4131
4132
|
offset: number().int().nonnegative(),
|
|
@@ -4185,6 +4186,14 @@ const webEditorInterface = defineInterface({
|
|
|
4185
4186
|
})),
|
|
4186
4187
|
getContentSchema: requestType(object({}), object({ schema: zJsonValue }))
|
|
4187
4188
|
});
|
|
4189
|
+
const webEditorHostTransportInterface = defineInterface({
|
|
4190
|
+
id: "web-editor-host-transport",
|
|
4191
|
+
description: "Optional messages the web editor sends to its host."
|
|
4192
|
+
}, { message: notificationType(object({ message: zJsonValue })) });
|
|
4193
|
+
const webEditorClientTransportInterface = defineInterface({
|
|
4194
|
+
id: "web-editor-client-transport",
|
|
4195
|
+
description: "Optional messages the web editor host sends to the editor."
|
|
4196
|
+
}, { message: notificationType(object({ message: zJsonValue })) });
|
|
4188
4197
|
/** Per-scope registration: `registered` (toolbar button) and `isDefault` (auto-open). */
|
|
4189
4198
|
const zScopeRegistration = object({
|
|
4190
4199
|
registered: boolean(),
|
|
@@ -4382,16 +4391,19 @@ var Emitter = class {
|
|
|
4382
4391
|
var WebEditorHost = class {
|
|
4383
4392
|
_connection;
|
|
4384
4393
|
_editor;
|
|
4394
|
+
_clientTransport;
|
|
4385
4395
|
_contentType;
|
|
4386
4396
|
_jsonFormat;
|
|
4387
4397
|
_onError;
|
|
4388
4398
|
_capabilities;
|
|
4399
|
+
_hostTransportSubscription;
|
|
4389
4400
|
_text;
|
|
4390
4401
|
_readOnly;
|
|
4391
4402
|
_serverRevision = 0;
|
|
4392
4403
|
_acknowledgedClientRevision = 0;
|
|
4393
4404
|
_editorInitialized = false;
|
|
4394
4405
|
_editorCapabilities;
|
|
4406
|
+
_pendingHostTransportMessages = [];
|
|
4395
4407
|
_onDidChangeText = new Emitter();
|
|
4396
4408
|
onDidChangeText = this._onDidChangeText.event;
|
|
4397
4409
|
_onDidInitialize = new Emitter();
|
|
@@ -4405,8 +4417,12 @@ var WebEditorHost = class {
|
|
|
4405
4417
|
this._readOnly = options.readOnly ?? false;
|
|
4406
4418
|
this._jsonFormat = options.jsonFormat ?? {};
|
|
4407
4419
|
this._onError = options.onError ?? ((m, d) => console.error("WebEditorHost:", m, d));
|
|
4408
|
-
this._capabilities =
|
|
4420
|
+
this._capabilities = {
|
|
4421
|
+
...options.capabilities ?? { supportsForceUpdate: true },
|
|
4422
|
+
supportsHostTransport: options.hostTransport ? true : void 0
|
|
4423
|
+
};
|
|
4409
4424
|
this._editor = this._connection.get(webEditorInterface);
|
|
4425
|
+
this._clientTransport = this._connection.get(webEditorClientTransportInterface);
|
|
4410
4426
|
this._connection.register(webEditorHostInterface, {
|
|
4411
4427
|
initialized: (params) => {
|
|
4412
4428
|
if (params.contentType !== this._contentType) this._onError(`Editor contentType "${params.contentType}" does not match host "${this._contentType}"`);
|
|
@@ -4415,6 +4431,7 @@ var WebEditorHost = class {
|
|
|
4415
4431
|
this._serverRevision = 0;
|
|
4416
4432
|
this._acknowledgedClientRevision = 0;
|
|
4417
4433
|
this._pushFullUpdate();
|
|
4434
|
+
for (const message of this._pendingHostTransportMessages.splice(0)) this._clientTransport.message({ message });
|
|
4418
4435
|
this._onDidInitialize.fire({ capabilities: params.capabilities });
|
|
4419
4436
|
return {
|
|
4420
4437
|
protocolVersion: "web-editor-host/0.12",
|
|
@@ -4459,6 +4476,13 @@ var WebEditorHost = class {
|
|
|
4459
4476
|
this._onDidReportSize.fire({ height: params.height });
|
|
4460
4477
|
}
|
|
4461
4478
|
});
|
|
4479
|
+
if (options.hostTransport) {
|
|
4480
|
+
this._connection.register(webEditorHostTransportInterface, { message: ({ message }) => options.hostTransport.sendMessage(message) });
|
|
4481
|
+
this._hostTransportSubscription = options.hostTransport.onMessage((message) => {
|
|
4482
|
+
if (this._editorInitialized) this._clientTransport.message({ message });
|
|
4483
|
+
else this._pendingHostTransportMessages.push(message);
|
|
4484
|
+
});
|
|
4485
|
+
}
|
|
4462
4486
|
}
|
|
4463
4487
|
/** The text the host believes the document currently holds. */
|
|
4464
4488
|
getText() {
|
|
@@ -4516,9 +4540,11 @@ var WebEditorHost = class {
|
|
|
4516
4540
|
});
|
|
4517
4541
|
}
|
|
4518
4542
|
dispose() {
|
|
4543
|
+
this._hostTransportSubscription?.dispose();
|
|
4519
4544
|
this._onDidChangeText.dispose();
|
|
4520
4545
|
this._onDidInitialize.dispose();
|
|
4521
4546
|
this._onDidReportSize.dispose();
|
|
4547
|
+
this._pendingHostTransportMessages.length = 0;
|
|
4522
4548
|
this._connection.close();
|
|
4523
4549
|
}
|
|
4524
4550
|
_pushFullUpdate(force) {
|
|
@@ -4697,11 +4723,15 @@ var HostConnection = class HostConnection {
|
|
|
4697
4723
|
var WebEditorClient = class WebEditorClient {
|
|
4698
4724
|
_connection;
|
|
4699
4725
|
_host;
|
|
4726
|
+
_hostTransportProxy;
|
|
4700
4727
|
_onError;
|
|
4728
|
+
_hostTransport;
|
|
4701
4729
|
_content = void 0;
|
|
4702
4730
|
_readOnly = false;
|
|
4703
4731
|
_options = void 0;
|
|
4704
4732
|
_hostCapabilities;
|
|
4733
|
+
_pendingHostTransportMessages = [];
|
|
4734
|
+
_hostTransportActivated = false;
|
|
4705
4735
|
_clientRevision = 0;
|
|
4706
4736
|
_basedOnServerRevision = 0;
|
|
4707
4737
|
/** Number of un-acked local revisions. While > 0 the editor has pending edits. */
|
|
@@ -4714,6 +4744,7 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4714
4744
|
onDidChangeReadOnly = this._onDidChangeReadOnly.event;
|
|
4715
4745
|
_onDidChangeOptions = new Emitter();
|
|
4716
4746
|
onDidChangeOptions = this._onDidChangeOptions.event;
|
|
4747
|
+
_onDidReceiveHostMessage = new Emitter();
|
|
4717
4748
|
/** Resolves once the host has acknowledged `initialized`. */
|
|
4718
4749
|
onDidConnect;
|
|
4719
4750
|
static async connect(options) {
|
|
@@ -4725,6 +4756,7 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4725
4756
|
this._connection = resolveConnection(options.connection);
|
|
4726
4757
|
this._onError = options.onError ?? ((m, d) => console.error("WebEditorClient:", m, d));
|
|
4727
4758
|
this._host = this._connection.get(webEditorHostInterface);
|
|
4759
|
+
this._hostTransportProxy = this._connection.get(webEditorHostTransportInterface);
|
|
4728
4760
|
this._connection.register(webEditorInterface, {
|
|
4729
4761
|
update: (params) => this._handleUpdate(params),
|
|
4730
4762
|
applyContentEdits: (params) => this._handleApplyContentEdits(params),
|
|
@@ -4732,12 +4764,28 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4732
4764
|
return { schema: options.getContentSchema ? await options.getContentSchema() : null };
|
|
4733
4765
|
}
|
|
4734
4766
|
});
|
|
4767
|
+
this._connection.register(webEditorClientTransportInterface, { message: ({ message }) => {
|
|
4768
|
+
if (this._hostTransportActivated) this._onDidReceiveHostMessage.fire(message);
|
|
4769
|
+
else this._pendingHostTransportMessages.push(message);
|
|
4770
|
+
} });
|
|
4735
4771
|
this.onDidConnect = this._host.initialized({
|
|
4736
4772
|
protocolVersion: "web-editor/0.12",
|
|
4737
4773
|
contentType: options.contentType ?? "text",
|
|
4738
4774
|
capabilities: options.capabilities
|
|
4739
4775
|
}).then((r) => {
|
|
4740
4776
|
this._hostCapabilities = r.capabilities;
|
|
4777
|
+
if (r.capabilities?.supportsHostTransport) this._hostTransport = {
|
|
4778
|
+
onMessage: (listener) => {
|
|
4779
|
+
const disposable = this._onDidReceiveHostMessage.event(listener);
|
|
4780
|
+
if (!this._hostTransportActivated) {
|
|
4781
|
+
this._hostTransportActivated = true;
|
|
4782
|
+
for (const message of this._pendingHostTransportMessages.splice(0)) listener(message);
|
|
4783
|
+
}
|
|
4784
|
+
return disposable;
|
|
4785
|
+
},
|
|
4786
|
+
sendMessage: (message) => this._hostTransportProxy.message({ message })
|
|
4787
|
+
};
|
|
4788
|
+
else this._pendingHostTransportMessages.length = 0;
|
|
4741
4789
|
return { capabilities: r.capabilities };
|
|
4742
4790
|
});
|
|
4743
4791
|
}
|
|
@@ -4749,6 +4797,10 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4749
4797
|
get connection() {
|
|
4750
4798
|
return this._connection;
|
|
4751
4799
|
}
|
|
4800
|
+
/** Optional notification transport supplied by the web editor host. */
|
|
4801
|
+
get hostTransport() {
|
|
4802
|
+
return this._hostTransport;
|
|
4803
|
+
}
|
|
4752
4804
|
getContent() {
|
|
4753
4805
|
return this._content;
|
|
4754
4806
|
}
|
|
@@ -4797,6 +4849,8 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4797
4849
|
this._onDidApplyHostEdits.dispose();
|
|
4798
4850
|
this._onDidChangeReadOnly.dispose();
|
|
4799
4851
|
this._onDidChangeOptions.dispose();
|
|
4852
|
+
this._onDidReceiveHostMessage.dispose();
|
|
4853
|
+
this._pendingHostTransportMessages.length = 0;
|
|
4800
4854
|
this._connection.close();
|
|
4801
4855
|
}
|
|
4802
4856
|
_handleUpdate(params) {
|
|
@@ -5047,6 +5101,6 @@ var VsCodeAppHostClient = class {
|
|
|
5047
5101
|
}
|
|
5048
5102
|
};
|
|
5049
5103
|
//#endregion
|
|
5050
|
-
export { EmbeddedAppHandle, VsCodeAppHostClient, WebEditorClient, WebEditorHost, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorHostInterface, webEditorInterface };
|
|
5104
|
+
export { EmbeddedAppHandle, VsCodeAppHostClient, WebEditorClient, WebEditorHost, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface };
|
|
5051
5105
|
|
|
5052
5106
|
//# sourceMappingURL=index.js.map
|