@vscode/web-editors 0.0.2-4 → 0.0.2-41
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 +45 -1
- package/dist/index.js +98 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -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;
|
|
@@ -2167,13 +2168,24 @@ declare const zContentEdit: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2167
2168
|
newText: ZodString;
|
|
2168
2169
|
}, $strip>>;
|
|
2169
2170
|
}, $strip>], "kind">;
|
|
2171
|
+
declare const zWebEditorUpdate: ZodObject<{
|
|
2172
|
+
content: ZodOptional<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>;
|
|
2173
|
+
options: ZodOptional<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>;
|
|
2174
|
+
readOnly: ZodOptional<ZodBoolean>;
|
|
2175
|
+
serverRevision: ZodOptional<ZodNumber>;
|
|
2176
|
+
acknowledgedClientRevision: ZodOptional<ZodNumber>;
|
|
2177
|
+
force: ZodOptional<ZodBoolean>;
|
|
2178
|
+
}, $strip>;
|
|
2170
2179
|
type ContentEdit = output<typeof zContentEdit>;
|
|
2171
2180
|
type TextEdit = output<typeof zTextEdit>;
|
|
2172
2181
|
type EditorCapabilities = output<typeof zEditorCapabilities>;
|
|
2173
2182
|
type HostCapabilities = output<typeof zHostCapabilities>;
|
|
2183
|
+
type WebEditorUpdate = output<typeof zWebEditorUpdate>;
|
|
2174
2184
|
type ContentType = "text" | "json";
|
|
2175
2185
|
declare const webEditorHostInterface: any;
|
|
2176
2186
|
declare const webEditorInterface: any;
|
|
2187
|
+
declare const webEditorHostTransportInterface: any;
|
|
2188
|
+
declare const webEditorClientTransportInterface: any;
|
|
2177
2189
|
declare const zEmbeddedAppDescriptor: ZodObject<{
|
|
2178
2190
|
handleId: ZodString;
|
|
2179
2191
|
appId: ZodString;
|
|
@@ -2196,6 +2208,8 @@ declare const vscodeAppEmbeddingEventsInterface: any;
|
|
|
2196
2208
|
type WebEditorHostProxy = InterfaceClient<typeof webEditorHostInterface>;
|
|
2197
2209
|
/** Typed proxy used by the host to invoke editor methods. */
|
|
2198
2210
|
type WebEditorProxy = InterfaceClient<typeof webEditorInterface>;
|
|
2211
|
+
type WebEditorHostTransportProxy = InterfaceClient<typeof webEditorHostTransportInterface>;
|
|
2212
|
+
type WebEditorClientTransportProxy = InterfaceClient<typeof webEditorClientTransportInterface>;
|
|
2199
2213
|
/** Typed proxy used by an app to invoke `vscode-app-host` methods. */
|
|
2200
2214
|
type VsCodeAppHostProxy = InterfaceClient<typeof vscodeAppHostInterface>;
|
|
2201
2215
|
type VsCodeAppEmbeddingEventsProxy = InterfaceClient<typeof vscodeAppEmbeddingEventsInterface>;
|
|
@@ -2271,6 +2285,16 @@ interface IDisposable {
|
|
|
2271
2285
|
type EventListener<T> = (event: T) => void;
|
|
2272
2286
|
type Event<T> = (listener: EventListener<T>) => IDisposable;
|
|
2273
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
|
|
2274
2298
|
//#region src/host/WebEditorHost.d.ts
|
|
2275
2299
|
interface WebEditorHostOptions {
|
|
2276
2300
|
/**
|
|
@@ -2293,6 +2317,8 @@ interface WebEditorHostOptions {
|
|
|
2293
2317
|
jsonFormat?: JsonFormatOptions;
|
|
2294
2318
|
/** Host capabilities advertised on `initialized`. */
|
|
2295
2319
|
capabilities?: HostCapabilities;
|
|
2320
|
+
/** Optional message transport to expose to the editor. */
|
|
2321
|
+
hostTransport?: HostTransport;
|
|
2296
2322
|
/** Called when the editor sends malformed input. Defaults to `console.error`. */
|
|
2297
2323
|
onError?: (message: string, detail?: unknown) => void;
|
|
2298
2324
|
}
|
|
@@ -2306,16 +2332,19 @@ interface WebEditorHostOptions {
|
|
|
2306
2332
|
declare class WebEditorHost implements IDisposable {
|
|
2307
2333
|
private readonly _connection;
|
|
2308
2334
|
private readonly _editor;
|
|
2335
|
+
private readonly _clientTransport;
|
|
2309
2336
|
private readonly _contentType;
|
|
2310
2337
|
private readonly _jsonFormat;
|
|
2311
2338
|
private readonly _onError;
|
|
2312
2339
|
private readonly _capabilities;
|
|
2340
|
+
private readonly _hostTransportSubscription;
|
|
2313
2341
|
private _text;
|
|
2314
2342
|
private _readOnly;
|
|
2315
2343
|
private _serverRevision;
|
|
2316
2344
|
private _acknowledgedClientRevision;
|
|
2317
2345
|
private _editorInitialized;
|
|
2318
2346
|
private _editorCapabilities;
|
|
2347
|
+
private readonly _pendingHostTransportMessages;
|
|
2319
2348
|
private readonly _onDidChangeText;
|
|
2320
2349
|
readonly onDidChangeText: Event<{
|
|
2321
2350
|
text: string;
|
|
@@ -2338,6 +2367,12 @@ declare class WebEditorHost implements IDisposable {
|
|
|
2338
2367
|
setText(text: string, opts?: {
|
|
2339
2368
|
force?: boolean;
|
|
2340
2369
|
}): void;
|
|
2370
|
+
/**
|
|
2371
|
+
* Reassign this host/editor connection to another logical document.
|
|
2372
|
+
* The forced update advances the server revision, making edits queued by
|
|
2373
|
+
* the previous logical document stale before the caller switches routing.
|
|
2374
|
+
*/
|
|
2375
|
+
reuse(text: string, readOnly: boolean): void;
|
|
2341
2376
|
getReadOnly(): boolean;
|
|
2342
2377
|
setReadOnly(readOnly: boolean): void;
|
|
2343
2378
|
/**
|
|
@@ -2347,6 +2382,8 @@ declare class WebEditorHost implements IDisposable {
|
|
|
2347
2382
|
applyEdits(edits: readonly ContentEdit[]): void;
|
|
2348
2383
|
dispose(): void;
|
|
2349
2384
|
private _pushFullUpdate;
|
|
2385
|
+
private _pushAcknowledgement;
|
|
2386
|
+
private _acknowledgeAndRestore;
|
|
2350
2387
|
}
|
|
2351
2388
|
//#endregion
|
|
2352
2389
|
//#region src/client/connection.d.ts
|
|
@@ -2446,11 +2483,15 @@ interface WebEditorClientState {
|
|
|
2446
2483
|
declare class WebEditorClient implements IDisposable {
|
|
2447
2484
|
private readonly _connection;
|
|
2448
2485
|
private readonly _host;
|
|
2486
|
+
private readonly _hostTransportProxy;
|
|
2449
2487
|
private readonly _onError;
|
|
2488
|
+
private _hostTransport;
|
|
2450
2489
|
private _content;
|
|
2451
2490
|
private _readOnly;
|
|
2452
2491
|
private _options;
|
|
2453
2492
|
private _hostCapabilities;
|
|
2493
|
+
private readonly _pendingHostTransportMessages;
|
|
2494
|
+
private _hostTransportActivated;
|
|
2454
2495
|
private _clientRevision;
|
|
2455
2496
|
private _basedOnServerRevision;
|
|
2456
2497
|
/** Number of un-acked local revisions. While > 0 the editor has pending edits. */
|
|
@@ -2473,6 +2514,7 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2473
2514
|
readonly onDidChangeOptions: Event<{
|
|
2474
2515
|
options: JsonValue;
|
|
2475
2516
|
}>;
|
|
2517
|
+
private readonly _onDidReceiveHostMessage;
|
|
2476
2518
|
/** Resolves once the host has acknowledged `initialized`. */
|
|
2477
2519
|
readonly onDidConnect: Promise<{
|
|
2478
2520
|
capabilities: HostCapabilities | undefined;
|
|
@@ -2485,6 +2527,8 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2485
2527
|
* second one.
|
|
2486
2528
|
*/
|
|
2487
2529
|
get connection(): HubRpcConnection;
|
|
2530
|
+
/** Optional notification transport supplied by the web editor host. */
|
|
2531
|
+
get hostTransport(): HostTransport | undefined;
|
|
2488
2532
|
getContent(): JsonValue;
|
|
2489
2533
|
getReadOnly(): boolean;
|
|
2490
2534
|
getOptions(): JsonValue;
|
|
@@ -2639,5 +2683,5 @@ declare class VsCodeAppHostClient {
|
|
|
2639
2683
|
}): Promise<EditorAssociationResult>;
|
|
2640
2684
|
}
|
|
2641
2685
|
//#endregion
|
|
2642
|
-
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, 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 };
|
|
2643
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(),
|
|
@@ -4141,6 +4142,14 @@ const zContentEdit = discriminatedUnion("kind", [object({
|
|
|
4141
4142
|
path: array(string()),
|
|
4142
4143
|
stringEdits: array(zTextEdit)
|
|
4143
4144
|
})]);
|
|
4145
|
+
const zWebEditorUpdate = object({
|
|
4146
|
+
content: zJsonValue.optional(),
|
|
4147
|
+
options: zJsonValue.optional(),
|
|
4148
|
+
readOnly: boolean().optional(),
|
|
4149
|
+
serverRevision: number().int().nonnegative().optional(),
|
|
4150
|
+
acknowledgedClientRevision: number().int().nonnegative().optional(),
|
|
4151
|
+
force: boolean().optional()
|
|
4152
|
+
});
|
|
4144
4153
|
const webEditorHostInterface = defineInterface({
|
|
4145
4154
|
id: "web-editor-host",
|
|
4146
4155
|
description: "Methods the host exposes to the editor (web-editor/0.12)."
|
|
@@ -4169,14 +4178,7 @@ const webEditorInterface = defineInterface({
|
|
|
4169
4178
|
id: "web-editor",
|
|
4170
4179
|
description: "Methods the editor exposes to the host (web-editor/0.12)."
|
|
4171
4180
|
}, {
|
|
4172
|
-
update: notificationType(
|
|
4173
|
-
content: zJsonValue.optional(),
|
|
4174
|
-
options: zJsonValue.optional(),
|
|
4175
|
-
readOnly: boolean().optional(),
|
|
4176
|
-
serverRevision: number().int().nonnegative().optional(),
|
|
4177
|
-
acknowledgedClientRevision: number().int().nonnegative().optional(),
|
|
4178
|
-
force: boolean().optional()
|
|
4179
|
-
})),
|
|
4181
|
+
update: notificationType(zWebEditorUpdate),
|
|
4180
4182
|
applyContentEdits: notificationType(object({
|
|
4181
4183
|
edits: array(zContentEdit),
|
|
4182
4184
|
serverRevision: number().int().nonnegative(),
|
|
@@ -4184,6 +4186,14 @@ const webEditorInterface = defineInterface({
|
|
|
4184
4186
|
})),
|
|
4185
4187
|
getContentSchema: requestType(object({}), object({ schema: zJsonValue }))
|
|
4186
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 })) });
|
|
4187
4197
|
/** Per-scope registration: `registered` (toolbar button) and `isDefault` (auto-open). */
|
|
4188
4198
|
const zScopeRegistration = object({
|
|
4189
4199
|
registered: boolean(),
|
|
@@ -4381,16 +4391,19 @@ var Emitter = class {
|
|
|
4381
4391
|
var WebEditorHost = class {
|
|
4382
4392
|
_connection;
|
|
4383
4393
|
_editor;
|
|
4394
|
+
_clientTransport;
|
|
4384
4395
|
_contentType;
|
|
4385
4396
|
_jsonFormat;
|
|
4386
4397
|
_onError;
|
|
4387
4398
|
_capabilities;
|
|
4399
|
+
_hostTransportSubscription;
|
|
4388
4400
|
_text;
|
|
4389
4401
|
_readOnly;
|
|
4390
4402
|
_serverRevision = 0;
|
|
4391
4403
|
_acknowledgedClientRevision = 0;
|
|
4392
4404
|
_editorInitialized = false;
|
|
4393
4405
|
_editorCapabilities;
|
|
4406
|
+
_pendingHostTransportMessages = [];
|
|
4394
4407
|
_onDidChangeText = new Emitter();
|
|
4395
4408
|
onDidChangeText = this._onDidChangeText.event;
|
|
4396
4409
|
_onDidInitialize = new Emitter();
|
|
@@ -4404,8 +4417,12 @@ var WebEditorHost = class {
|
|
|
4404
4417
|
this._readOnly = options.readOnly ?? false;
|
|
4405
4418
|
this._jsonFormat = options.jsonFormat ?? {};
|
|
4406
4419
|
this._onError = options.onError ?? ((m, d) => console.error("WebEditorHost:", m, d));
|
|
4407
|
-
this._capabilities =
|
|
4420
|
+
this._capabilities = {
|
|
4421
|
+
...options.capabilities ?? { supportsForceUpdate: true },
|
|
4422
|
+
supportsHostTransport: options.hostTransport ? true : void 0
|
|
4423
|
+
};
|
|
4408
4424
|
this._editor = this._connection.get(webEditorInterface);
|
|
4425
|
+
this._clientTransport = this._connection.get(webEditorClientTransportInterface);
|
|
4409
4426
|
this._connection.register(webEditorHostInterface, {
|
|
4410
4427
|
initialized: (params) => {
|
|
4411
4428
|
if (params.contentType !== this._contentType) this._onError(`Editor contentType "${params.contentType}" does not match host "${this._contentType}"`);
|
|
@@ -4414,6 +4431,7 @@ var WebEditorHost = class {
|
|
|
4414
4431
|
this._serverRevision = 0;
|
|
4415
4432
|
this._acknowledgedClientRevision = 0;
|
|
4416
4433
|
this._pushFullUpdate();
|
|
4434
|
+
for (const message of this._pendingHostTransportMessages.splice(0)) this._clientTransport.message({ message });
|
|
4417
4435
|
this._onDidInitialize.fire({ capabilities: params.capabilities });
|
|
4418
4436
|
return {
|
|
4419
4437
|
protocolVersion: "web-editor-host/0.12",
|
|
@@ -4423,6 +4441,12 @@ var WebEditorHost = class {
|
|
|
4423
4441
|
applyContentEdit: (params) => {
|
|
4424
4442
|
if (this._readOnly) {
|
|
4425
4443
|
this._onError("Editor sent applyContentEdit while readOnly");
|
|
4444
|
+
this._acknowledgeAndRestore(params.clientRevision);
|
|
4445
|
+
return;
|
|
4446
|
+
}
|
|
4447
|
+
if (params.basedOnServerRevision !== this._serverRevision) {
|
|
4448
|
+
this._onError(`Editor edit is based on stale server revision ${params.basedOnServerRevision}; current revision is ${this._serverRevision}`);
|
|
4449
|
+
this._acknowledgeAndRestore(params.clientRevision);
|
|
4426
4450
|
return;
|
|
4427
4451
|
}
|
|
4428
4452
|
let newValue;
|
|
@@ -4430,6 +4454,7 @@ var WebEditorHost = class {
|
|
|
4430
4454
|
newValue = applyContentEdits(encodeForEditor(this._text, this._contentType), params.edits);
|
|
4431
4455
|
} catch (e) {
|
|
4432
4456
|
this._onError("Failed to apply content edits from editor", e);
|
|
4457
|
+
this._acknowledgeAndRestore(params.clientRevision);
|
|
4433
4458
|
return;
|
|
4434
4459
|
}
|
|
4435
4460
|
let newText;
|
|
@@ -4437,18 +4462,27 @@ var WebEditorHost = class {
|
|
|
4437
4462
|
newText = decodeFromEditor(newValue, this._contentType, this._jsonFormat);
|
|
4438
4463
|
} catch (e) {
|
|
4439
4464
|
this._onError("Failed to decode editor content", e);
|
|
4465
|
+
this._acknowledgeAndRestore(params.clientRevision);
|
|
4440
4466
|
return;
|
|
4441
4467
|
}
|
|
4442
|
-
this._acknowledgedClientRevision = params.clientRevision;
|
|
4468
|
+
this._acknowledgedClientRevision = Math.max(this._acknowledgedClientRevision, params.clientRevision);
|
|
4443
4469
|
if (newText !== this._text) {
|
|
4444
4470
|
this._text = newText;
|
|
4445
4471
|
this._onDidChangeText.fire({ text: newText });
|
|
4446
4472
|
}
|
|
4473
|
+
this._pushAcknowledgement();
|
|
4447
4474
|
},
|
|
4448
4475
|
reportSize: (params) => {
|
|
4449
4476
|
this._onDidReportSize.fire({ height: params.height });
|
|
4450
4477
|
}
|
|
4451
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
|
+
}
|
|
4452
4486
|
}
|
|
4453
4487
|
/** The text the host believes the document currently holds. */
|
|
4454
4488
|
getText() {
|
|
@@ -4459,10 +4493,20 @@ var WebEditorHost = class {
|
|
|
4459
4493
|
* root. If `force`, the editor must adopt it even with pending local edits.
|
|
4460
4494
|
*/
|
|
4461
4495
|
setText(text, opts = {}) {
|
|
4462
|
-
if (text === this._text) return;
|
|
4496
|
+
if (text === this._text && !opts.force) return;
|
|
4463
4497
|
this._text = text;
|
|
4464
4498
|
this._pushFullUpdate(opts.force);
|
|
4465
4499
|
}
|
|
4500
|
+
/**
|
|
4501
|
+
* Reassign this host/editor connection to another logical document.
|
|
4502
|
+
* The forced update advances the server revision, making edits queued by
|
|
4503
|
+
* the previous logical document stale before the caller switches routing.
|
|
4504
|
+
*/
|
|
4505
|
+
reuse(text, readOnly) {
|
|
4506
|
+
this._readOnly = readOnly;
|
|
4507
|
+
this._text = text;
|
|
4508
|
+
this._pushFullUpdate(true);
|
|
4509
|
+
}
|
|
4466
4510
|
getReadOnly() {
|
|
4467
4511
|
return this._readOnly;
|
|
4468
4512
|
}
|
|
@@ -4496,9 +4540,11 @@ var WebEditorHost = class {
|
|
|
4496
4540
|
});
|
|
4497
4541
|
}
|
|
4498
4542
|
dispose() {
|
|
4543
|
+
this._hostTransportSubscription?.dispose();
|
|
4499
4544
|
this._onDidChangeText.dispose();
|
|
4500
4545
|
this._onDidInitialize.dispose();
|
|
4501
4546
|
this._onDidReportSize.dispose();
|
|
4547
|
+
this._pendingHostTransportMessages.length = 0;
|
|
4502
4548
|
this._connection.close();
|
|
4503
4549
|
}
|
|
4504
4550
|
_pushFullUpdate(force) {
|
|
@@ -4519,6 +4565,17 @@ var WebEditorHost = class {
|
|
|
4519
4565
|
force
|
|
4520
4566
|
});
|
|
4521
4567
|
}
|
|
4568
|
+
_pushAcknowledgement() {
|
|
4569
|
+
if (!this._editorInitialized) return;
|
|
4570
|
+
this._editor.update({
|
|
4571
|
+
serverRevision: this._serverRevision,
|
|
4572
|
+
acknowledgedClientRevision: this._acknowledgedClientRevision
|
|
4573
|
+
});
|
|
4574
|
+
}
|
|
4575
|
+
_acknowledgeAndRestore(clientRevision) {
|
|
4576
|
+
this._acknowledgedClientRevision = Math.max(this._acknowledgedClientRevision, clientRevision);
|
|
4577
|
+
this._pushFullUpdate(true);
|
|
4578
|
+
}
|
|
4522
4579
|
};
|
|
4523
4580
|
//#endregion
|
|
4524
4581
|
//#region src/client/connection.ts
|
|
@@ -4666,11 +4723,15 @@ var HostConnection = class HostConnection {
|
|
|
4666
4723
|
var WebEditorClient = class WebEditorClient {
|
|
4667
4724
|
_connection;
|
|
4668
4725
|
_host;
|
|
4726
|
+
_hostTransportProxy;
|
|
4669
4727
|
_onError;
|
|
4728
|
+
_hostTransport;
|
|
4670
4729
|
_content = void 0;
|
|
4671
4730
|
_readOnly = false;
|
|
4672
4731
|
_options = void 0;
|
|
4673
4732
|
_hostCapabilities;
|
|
4733
|
+
_pendingHostTransportMessages = [];
|
|
4734
|
+
_hostTransportActivated = false;
|
|
4674
4735
|
_clientRevision = 0;
|
|
4675
4736
|
_basedOnServerRevision = 0;
|
|
4676
4737
|
/** Number of un-acked local revisions. While > 0 the editor has pending edits. */
|
|
@@ -4683,6 +4744,7 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4683
4744
|
onDidChangeReadOnly = this._onDidChangeReadOnly.event;
|
|
4684
4745
|
_onDidChangeOptions = new Emitter();
|
|
4685
4746
|
onDidChangeOptions = this._onDidChangeOptions.event;
|
|
4747
|
+
_onDidReceiveHostMessage = new Emitter();
|
|
4686
4748
|
/** Resolves once the host has acknowledged `initialized`. */
|
|
4687
4749
|
onDidConnect;
|
|
4688
4750
|
static async connect(options) {
|
|
@@ -4694,6 +4756,7 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4694
4756
|
this._connection = resolveConnection(options.connection);
|
|
4695
4757
|
this._onError = options.onError ?? ((m, d) => console.error("WebEditorClient:", m, d));
|
|
4696
4758
|
this._host = this._connection.get(webEditorHostInterface);
|
|
4759
|
+
this._hostTransportProxy = this._connection.get(webEditorHostTransportInterface);
|
|
4697
4760
|
this._connection.register(webEditorInterface, {
|
|
4698
4761
|
update: (params) => this._handleUpdate(params),
|
|
4699
4762
|
applyContentEdits: (params) => this._handleApplyContentEdits(params),
|
|
@@ -4701,12 +4764,28 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4701
4764
|
return { schema: options.getContentSchema ? await options.getContentSchema() : null };
|
|
4702
4765
|
}
|
|
4703
4766
|
});
|
|
4767
|
+
this._connection.register(webEditorClientTransportInterface, { message: ({ message }) => {
|
|
4768
|
+
if (this._hostTransportActivated) this._onDidReceiveHostMessage.fire(message);
|
|
4769
|
+
else this._pendingHostTransportMessages.push(message);
|
|
4770
|
+
} });
|
|
4704
4771
|
this.onDidConnect = this._host.initialized({
|
|
4705
4772
|
protocolVersion: "web-editor/0.12",
|
|
4706
4773
|
contentType: options.contentType ?? "text",
|
|
4707
4774
|
capabilities: options.capabilities
|
|
4708
4775
|
}).then((r) => {
|
|
4709
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;
|
|
4710
4789
|
return { capabilities: r.capabilities };
|
|
4711
4790
|
});
|
|
4712
4791
|
}
|
|
@@ -4718,6 +4797,10 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4718
4797
|
get connection() {
|
|
4719
4798
|
return this._connection;
|
|
4720
4799
|
}
|
|
4800
|
+
/** Optional notification transport supplied by the web editor host. */
|
|
4801
|
+
get hostTransport() {
|
|
4802
|
+
return this._hostTransport;
|
|
4803
|
+
}
|
|
4721
4804
|
getContent() {
|
|
4722
4805
|
return this._content;
|
|
4723
4806
|
}
|
|
@@ -4766,6 +4849,8 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4766
4849
|
this._onDidApplyHostEdits.dispose();
|
|
4767
4850
|
this._onDidChangeReadOnly.dispose();
|
|
4768
4851
|
this._onDidChangeOptions.dispose();
|
|
4852
|
+
this._onDidReceiveHostMessage.dispose();
|
|
4853
|
+
this._pendingHostTransportMessages.length = 0;
|
|
4769
4854
|
this._connection.close();
|
|
4770
4855
|
}
|
|
4771
4856
|
_handleUpdate(params) {
|
|
@@ -5016,6 +5101,6 @@ var VsCodeAppHostClient = class {
|
|
|
5016
5101
|
}
|
|
5017
5102
|
};
|
|
5018
5103
|
//#endregion
|
|
5019
|
-
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 };
|
|
5020
5105
|
|
|
5021
5106
|
//# sourceMappingURL=index.js.map
|