@vscode/web-editors 0.0.2-11 → 0.0.2-111
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 +113 -3
- package/dist/index.js +212 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2143,11 +2143,14 @@ declare const ZodReadonly: $constructor<ZodReadonly>;
|
|
|
2143
2143
|
declare const zEditorCapabilities: ZodObject<{
|
|
2144
2144
|
supportsContentEdits: ZodOptional<ZodBoolean>;
|
|
2145
2145
|
supportsOptions: ZodOptional<ZodBoolean>;
|
|
2146
|
+
supportsPresentation: ZodOptional<ZodBoolean>;
|
|
2146
2147
|
}, $strip>;
|
|
2147
2148
|
declare const zHostCapabilities: ZodObject<{
|
|
2148
2149
|
supportsContentEdits: ZodOptional<ZodBoolean>;
|
|
2149
2150
|
supportsOptions: ZodOptional<ZodBoolean>;
|
|
2150
2151
|
supportsForceUpdate: ZodOptional<ZodBoolean>;
|
|
2152
|
+
supportsHostTransport: ZodOptional<ZodBoolean>;
|
|
2153
|
+
supportsPresentation: ZodOptional<ZodBoolean>;
|
|
2151
2154
|
}, $strip>;
|
|
2152
2155
|
declare const zTextEdit: ZodObject<{
|
|
2153
2156
|
offset: ZodNumber;
|
|
@@ -2175,14 +2178,39 @@ declare const zWebEditorUpdate: ZodObject<{
|
|
|
2175
2178
|
acknowledgedClientRevision: ZodOptional<ZodNumber>;
|
|
2176
2179
|
force: ZodOptional<ZodBoolean>;
|
|
2177
2180
|
}, $strip>;
|
|
2181
|
+
/** How an embedding host currently presents the editor. */
|
|
2182
|
+
declare const zPresentationMode: ZodEnum<{
|
|
2183
|
+
inline: "inline";
|
|
2184
|
+
"full-width": "full-width";
|
|
2185
|
+
"full-view": "full-view";
|
|
2186
|
+
}>;
|
|
2187
|
+
/**
|
|
2188
|
+
* Presentation controls the editor asks its embedding host for. The host's own
|
|
2189
|
+
* configuration takes precedence over these preferences.
|
|
2190
|
+
*/
|
|
2191
|
+
declare const zPresentationPreferences: ZodObject<{
|
|
2192
|
+
resizable: ZodOptional<ZodBoolean>;
|
|
2193
|
+
fullWidth: ZodOptional<ZodBoolean>;
|
|
2194
|
+
fullView: ZodOptional<ZodBoolean>;
|
|
2195
|
+
minHeight: ZodOptional<ZodNumber>;
|
|
2196
|
+
maxAutomaticHeight: ZodOptional<ZodNumber>;
|
|
2197
|
+
}, $strip>;
|
|
2178
2198
|
type ContentEdit = output<typeof zContentEdit>;
|
|
2179
2199
|
type TextEdit = output<typeof zTextEdit>;
|
|
2180
2200
|
type EditorCapabilities = output<typeof zEditorCapabilities>;
|
|
2181
2201
|
type HostCapabilities = output<typeof zHostCapabilities>;
|
|
2182
2202
|
type WebEditorUpdate = output<typeof zWebEditorUpdate>;
|
|
2203
|
+
type PresentationMode = output<typeof zPresentationMode>;
|
|
2204
|
+
type PresentationPreferences = output<typeof zPresentationPreferences>;
|
|
2183
2205
|
type ContentType = "text" | "json";
|
|
2184
2206
|
declare const webEditorHostInterface: any;
|
|
2185
2207
|
declare const webEditorInterface: any;
|
|
2208
|
+
declare const webEditorHostTransportInterface: any;
|
|
2209
|
+
declare const webEditorClientTransportInterface: any;
|
|
2210
|
+
/** Methods the editor exposes to a presenting host. */
|
|
2211
|
+
declare const webEditorPresentationInterface: any;
|
|
2212
|
+
/** Methods a presenting host exposes to the editor. */
|
|
2213
|
+
declare const webEditorPresentationHostInterface: any;
|
|
2186
2214
|
declare const zEmbeddedAppDescriptor: ZodObject<{
|
|
2187
2215
|
handleId: ZodString;
|
|
2188
2216
|
appId: ZodString;
|
|
@@ -2205,6 +2233,10 @@ declare const vscodeAppEmbeddingEventsInterface: any;
|
|
|
2205
2233
|
type WebEditorHostProxy = InterfaceClient<typeof webEditorHostInterface>;
|
|
2206
2234
|
/** Typed proxy used by the host to invoke editor methods. */
|
|
2207
2235
|
type WebEditorProxy = InterfaceClient<typeof webEditorInterface>;
|
|
2236
|
+
type WebEditorHostTransportProxy = InterfaceClient<typeof webEditorHostTransportInterface>;
|
|
2237
|
+
type WebEditorClientTransportProxy = InterfaceClient<typeof webEditorClientTransportInterface>;
|
|
2238
|
+
type WebEditorPresentationProxy = InterfaceClient<typeof webEditorPresentationInterface>;
|
|
2239
|
+
type WebEditorPresentationHostProxy = InterfaceClient<typeof webEditorPresentationHostInterface>;
|
|
2208
2240
|
/** Typed proxy used by an app to invoke `vscode-app-host` methods. */
|
|
2209
2241
|
type VsCodeAppHostProxy = InterfaceClient<typeof vscodeAppHostInterface>;
|
|
2210
2242
|
type VsCodeAppEmbeddingEventsProxy = InterfaceClient<typeof vscodeAppEmbeddingEventsInterface>;
|
|
@@ -2280,6 +2312,16 @@ interface IDisposable {
|
|
|
2280
2312
|
type EventListener<T> = (event: T) => void;
|
|
2281
2313
|
type Event<T> = (listener: EventListener<T>) => IDisposable;
|
|
2282
2314
|
//#endregion
|
|
2315
|
+
//#region src/hostTransport.d.ts
|
|
2316
|
+
/**
|
|
2317
|
+
* Optional message transport between a web editor and its host.
|
|
2318
|
+
*/
|
|
2319
|
+
interface HostTransport {
|
|
2320
|
+
readonly onMessage: Event<JsonValue>;
|
|
2321
|
+
/** Sends a notification to the host. */
|
|
2322
|
+
sendMessage(message: JsonValue): void;
|
|
2323
|
+
}
|
|
2324
|
+
//#endregion
|
|
2283
2325
|
//#region src/host/WebEditorHost.d.ts
|
|
2284
2326
|
interface WebEditorHostOptions {
|
|
2285
2327
|
/**
|
|
@@ -2302,6 +2344,14 @@ interface WebEditorHostOptions {
|
|
|
2302
2344
|
jsonFormat?: JsonFormatOptions;
|
|
2303
2345
|
/** Host capabilities advertised on `initialized`. */
|
|
2304
2346
|
capabilities?: HostCapabilities;
|
|
2347
|
+
/** Optional message transport to expose to the editor. */
|
|
2348
|
+
hostTransport?: HostTransport;
|
|
2349
|
+
/**
|
|
2350
|
+
* The host presents the editor inline (for example as a block in a document)
|
|
2351
|
+
* and exchanges presentation state with editors that support it: see
|
|
2352
|
+
* {@link WebEditorHost.setPresentationMode} and the presentation events.
|
|
2353
|
+
*/
|
|
2354
|
+
supportsPresentation?: boolean;
|
|
2305
2355
|
/** Called when the editor sends malformed input. Defaults to `console.error`. */
|
|
2306
2356
|
onError?: (message: string, detail?: unknown) => void;
|
|
2307
2357
|
}
|
|
@@ -2315,16 +2365,21 @@ interface WebEditorHostOptions {
|
|
|
2315
2365
|
declare class WebEditorHost implements IDisposable {
|
|
2316
2366
|
private readonly _connection;
|
|
2317
2367
|
private readonly _editor;
|
|
2368
|
+
private readonly _clientTransport;
|
|
2369
|
+
private readonly _presentation;
|
|
2318
2370
|
private readonly _contentType;
|
|
2319
2371
|
private readonly _jsonFormat;
|
|
2320
2372
|
private readonly _onError;
|
|
2321
2373
|
private readonly _capabilities;
|
|
2374
|
+
private readonly _hostTransportSubscription;
|
|
2322
2375
|
private _text;
|
|
2323
2376
|
private _readOnly;
|
|
2377
|
+
private _presentationMode;
|
|
2324
2378
|
private _serverRevision;
|
|
2325
2379
|
private _acknowledgedClientRevision;
|
|
2326
2380
|
private _editorInitialized;
|
|
2327
2381
|
private _editorCapabilities;
|
|
2382
|
+
private readonly _pendingHostTransportMessages;
|
|
2328
2383
|
private readonly _onDidChangeText;
|
|
2329
2384
|
readonly onDidChangeText: Event<{
|
|
2330
2385
|
text: string;
|
|
@@ -2337,6 +2392,12 @@ declare class WebEditorHost implements IDisposable {
|
|
|
2337
2392
|
readonly onDidReportSize: Event<{
|
|
2338
2393
|
height: number;
|
|
2339
2394
|
}>;
|
|
2395
|
+
private readonly _onDidSetPresentationPreferences;
|
|
2396
|
+
/** The editor replaced its presentation preferences. Only fires with `supportsPresentation`. */
|
|
2397
|
+
readonly onDidSetPresentationPreferences: Event<PresentationPreferences>;
|
|
2398
|
+
private readonly _onDidRequestExitFullView;
|
|
2399
|
+
/** The editor asked to leave full view. Only fires with `supportsPresentation`. */
|
|
2400
|
+
readonly onDidRequestExitFullView: Event<void>;
|
|
2340
2401
|
constructor(options: WebEditorHostOptions);
|
|
2341
2402
|
/** The text the host believes the document currently holds. */
|
|
2342
2403
|
getText(): string;
|
|
@@ -2354,6 +2415,11 @@ declare class WebEditorHost implements IDisposable {
|
|
|
2354
2415
|
*/
|
|
2355
2416
|
reuse(text: string, readOnly: boolean): void;
|
|
2356
2417
|
getReadOnly(): boolean;
|
|
2418
|
+
/**
|
|
2419
|
+
* Tell the editor how the host presents it. Sent to editors that support
|
|
2420
|
+
* presentation once they initialized, and again after they reconnect.
|
|
2421
|
+
*/
|
|
2422
|
+
setPresentationMode(mode: PresentationMode): void;
|
|
2357
2423
|
setReadOnly(readOnly: boolean): void;
|
|
2358
2424
|
/**
|
|
2359
2425
|
* Push fine-grained edits to the editor.
|
|
@@ -2363,6 +2429,7 @@ declare class WebEditorHost implements IDisposable {
|
|
|
2363
2429
|
dispose(): void;
|
|
2364
2430
|
private _pushFullUpdate;
|
|
2365
2431
|
private _pushAcknowledgement;
|
|
2432
|
+
private _pushPresentationMode;
|
|
2366
2433
|
private _acknowledgeAndRestore;
|
|
2367
2434
|
}
|
|
2368
2435
|
//#endregion
|
|
@@ -2463,11 +2530,19 @@ interface WebEditorClientState {
|
|
|
2463
2530
|
declare class WebEditorClient implements IDisposable {
|
|
2464
2531
|
private readonly _connection;
|
|
2465
2532
|
private readonly _host;
|
|
2533
|
+
private readonly _hostTransportProxy;
|
|
2534
|
+
private readonly _presentationHost;
|
|
2466
2535
|
private readonly _onError;
|
|
2536
|
+
private _hostTransport;
|
|
2467
2537
|
private _content;
|
|
2468
2538
|
private _readOnly;
|
|
2469
2539
|
private _options;
|
|
2470
2540
|
private _hostCapabilities;
|
|
2541
|
+
private _connected;
|
|
2542
|
+
private _presentationMode;
|
|
2543
|
+
private _presentationPreferences;
|
|
2544
|
+
private readonly _pendingHostTransportMessages;
|
|
2545
|
+
private _hostTransportActivated;
|
|
2471
2546
|
private _clientRevision;
|
|
2472
2547
|
private _basedOnServerRevision;
|
|
2473
2548
|
/** Number of un-acked local revisions. While > 0 the editor has pending edits. */
|
|
@@ -2490,6 +2565,12 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2490
2565
|
readonly onDidChangeOptions: Event<{
|
|
2491
2566
|
options: JsonValue;
|
|
2492
2567
|
}>;
|
|
2568
|
+
private readonly _onDidChangePresentationMode;
|
|
2569
|
+
/** The embedding host changed how it presents this editor. See {@link getPresentationMode}. */
|
|
2570
|
+
readonly onDidChangePresentationMode: Event<{
|
|
2571
|
+
mode: PresentationMode;
|
|
2572
|
+
}>;
|
|
2573
|
+
private readonly _onDidReceiveHostMessage;
|
|
2493
2574
|
/** Resolves once the host has acknowledged `initialized`. */
|
|
2494
2575
|
readonly onDidConnect: Promise<{
|
|
2495
2576
|
capabilities: HostCapabilities | undefined;
|
|
@@ -2502,6 +2583,8 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2502
2583
|
* second one.
|
|
2503
2584
|
*/
|
|
2504
2585
|
get connection(): HubRpcConnection;
|
|
2586
|
+
/** Optional notification transport supplied by the web editor host. */
|
|
2587
|
+
get hostTransport(): HostTransport | undefined;
|
|
2505
2588
|
getContent(): JsonValue;
|
|
2506
2589
|
getReadOnly(): boolean;
|
|
2507
2590
|
getOptions(): JsonValue;
|
|
@@ -2512,10 +2595,24 @@ declare class WebEditorClient implements IDisposable {
|
|
|
2512
2595
|
*/
|
|
2513
2596
|
applyEdits(edits: readonly ContentEdit[]): void;
|
|
2514
2597
|
/**
|
|
2515
|
-
* Report the editor's
|
|
2516
|
-
*
|
|
2598
|
+
* Report the editor's preferred content height (px): the height it needs to
|
|
2599
|
+
* show its content without scrolling, independent of the frame's current
|
|
2600
|
+
* height. A host embedding this editor in an iframe sizes the frame to it.
|
|
2517
2601
|
*/
|
|
2518
2602
|
reportSize(height: number): void;
|
|
2603
|
+
/**
|
|
2604
|
+
* How an embedding host currently presents this editor, or `undefined` when
|
|
2605
|
+
* the host does not present it inline (for example a standalone editor).
|
|
2606
|
+
*/
|
|
2607
|
+
getPresentationMode(): PresentationMode | undefined;
|
|
2608
|
+
/**
|
|
2609
|
+
* Ask a presenting host for presentation controls (resize grips, full view).
|
|
2610
|
+
* Replaces earlier preferences; sent once connected, and ignored by hosts
|
|
2611
|
+
* that do not present the editor inline.
|
|
2612
|
+
*/
|
|
2613
|
+
setPresentationPreferences(preferences: PresentationPreferences): void;
|
|
2614
|
+
/** Ask a presenting host to leave full view. */
|
|
2615
|
+
exitFullView(): void;
|
|
2519
2616
|
dispose(): void;
|
|
2520
2617
|
private _handleUpdate;
|
|
2521
2618
|
private _handleApplyContentEdits;
|
|
@@ -2654,7 +2751,20 @@ declare class VsCodeAppHostClient {
|
|
|
2654
2751
|
configureEditorAssociation(extension: string, options?: {
|
|
2655
2752
|
dismissable?: boolean;
|
|
2656
2753
|
}): Promise<EditorAssociationResult>;
|
|
2754
|
+
/**
|
|
2755
|
+
* This editor tab's view state, or `undefined` when none is set. VS Code
|
|
2756
|
+
* restores it with the tab (for example after a window reload); a newly
|
|
2757
|
+
* opened tab starts without one. Validate it like any other persisted
|
|
2758
|
+
* input, since it may come from an older version of the app.
|
|
2759
|
+
*/
|
|
2760
|
+
getViewState(): Promise<unknown>;
|
|
2761
|
+
/**
|
|
2762
|
+
* Replace this editor tab's view state with a JSON value, for example
|
|
2763
|
+
* scroll positions or selections. Use per-app storage for state shared by
|
|
2764
|
+
* every tab. Rejects for values too large to persist and in embedded apps.
|
|
2765
|
+
*/
|
|
2766
|
+
setViewState(value: unknown): Promise<void>;
|
|
2657
2767
|
}
|
|
2658
2768
|
//#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 };
|
|
2769
|
+
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, PresentationMode, PresentationPreferences, ScopeRegistration, TextEdit, VsCodeAppEmbeddingEventsProxy, VsCodeAppHostClient, VsCodeAppHostClientOptions, VsCodeAppHostProxy, WebEditorClient, WebEditorClientOptions, WebEditorClientState, WebEditorClientTransportProxy, WebEditorHost, WebEditorHostOptions, WebEditorHostProxy, WebEditorHostTransportProxy, WebEditorPresentationHostProxy, WebEditorPresentationProxy, WebEditorProxy, WebEditorUpdate, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface, webEditorPresentationHostInterface, webEditorPresentationInterface };
|
|
2660
2770
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -4120,12 +4120,17 @@ function superRefine(fn, params) {
|
|
|
4120
4120
|
const zJsonValue = unknown();
|
|
4121
4121
|
const zEditorCapabilities = object({
|
|
4122
4122
|
supportsContentEdits: boolean().optional(),
|
|
4123
|
-
supportsOptions: boolean().optional()
|
|
4123
|
+
supportsOptions: boolean().optional(),
|
|
4124
|
+
/** The editor implements `web-editor-presentation` (see {@link webEditorPresentationInterface}). */
|
|
4125
|
+
supportsPresentation: boolean().optional()
|
|
4124
4126
|
});
|
|
4125
4127
|
const zHostCapabilities = object({
|
|
4126
4128
|
supportsContentEdits: boolean().optional(),
|
|
4127
4129
|
supportsOptions: boolean().optional(),
|
|
4128
|
-
supportsForceUpdate: boolean().optional()
|
|
4130
|
+
supportsForceUpdate: boolean().optional(),
|
|
4131
|
+
supportsHostTransport: boolean().optional(),
|
|
4132
|
+
/** The host presents the editor inline and implements `web-editor-presentation-host`. */
|
|
4133
|
+
supportsPresentation: boolean().optional()
|
|
4129
4134
|
});
|
|
4130
4135
|
const zTextEdit = object({
|
|
4131
4136
|
offset: number().int().nonnegative(),
|
|
@@ -4149,6 +4154,28 @@ const zWebEditorUpdate = object({
|
|
|
4149
4154
|
acknowledgedClientRevision: number().int().nonnegative().optional(),
|
|
4150
4155
|
force: boolean().optional()
|
|
4151
4156
|
});
|
|
4157
|
+
/** How an embedding host currently presents the editor. */
|
|
4158
|
+
const zPresentationMode = _enum([
|
|
4159
|
+
"inline",
|
|
4160
|
+
"full-width",
|
|
4161
|
+
"full-view"
|
|
4162
|
+
]);
|
|
4163
|
+
const zEditorHeight = number().positive().max(1e4);
|
|
4164
|
+
/**
|
|
4165
|
+
* Presentation controls the editor asks its embedding host for. The host's own
|
|
4166
|
+
* configuration takes precedence over these preferences.
|
|
4167
|
+
*/
|
|
4168
|
+
const zPresentationPreferences = object({
|
|
4169
|
+
/** A height grip; dragging near the automatic (content) height snaps back to it. */
|
|
4170
|
+
resizable: boolean().optional(),
|
|
4171
|
+
/** A width grip that widens the editor up to the host's viewport. */
|
|
4172
|
+
fullWidth: boolean().optional(),
|
|
4173
|
+
/** A toolbar action that fills the host's viewport. */
|
|
4174
|
+
fullView: boolean().optional(),
|
|
4175
|
+
minHeight: zEditorHeight.optional(),
|
|
4176
|
+
/** Upper bound for the automatic height; users can still resize beyond it. */
|
|
4177
|
+
maxAutomaticHeight: zEditorHeight.optional()
|
|
4178
|
+
});
|
|
4152
4179
|
const webEditorHostInterface = defineInterface({
|
|
4153
4180
|
id: "web-editor-host",
|
|
4154
4181
|
description: "Methods the host exposes to the editor (web-editor/0.12)."
|
|
@@ -4167,9 +4194,12 @@ const webEditorHostInterface = defineInterface({
|
|
|
4167
4194
|
basedOnServerRevision: number().int().nonnegative()
|
|
4168
4195
|
})),
|
|
4169
4196
|
/**
|
|
4170
|
-
* The editor reports its
|
|
4171
|
-
*
|
|
4172
|
-
*
|
|
4197
|
+
* The editor reports its preferred content height (px): the height it needs
|
|
4198
|
+
* to show its content without scrolling, independent of the frame's current
|
|
4199
|
+
* height. Measure the content, not the viewport or document, which follow
|
|
4200
|
+
* the frame. An embedding host that reserves block space (e.g. an iframe
|
|
4201
|
+
* with no intrinsic height) sizes the frame to it and uses it as the
|
|
4202
|
+
* automatic height that user resizing snaps back to.
|
|
4173
4203
|
*/
|
|
4174
4204
|
reportSize: notificationType(object({ height: number().nonnegative() }))
|
|
4175
4205
|
});
|
|
@@ -4185,6 +4215,31 @@ const webEditorInterface = defineInterface({
|
|
|
4185
4215
|
})),
|
|
4186
4216
|
getContentSchema: requestType(object({}), object({ schema: zJsonValue }))
|
|
4187
4217
|
});
|
|
4218
|
+
const webEditorHostTransportInterface = defineInterface({
|
|
4219
|
+
id: "web-editor-host-transport",
|
|
4220
|
+
description: "Optional messages the web editor sends to its host."
|
|
4221
|
+
}, { message: notificationType(object({ message: zJsonValue })) });
|
|
4222
|
+
const webEditorClientTransportInterface = defineInterface({
|
|
4223
|
+
id: "web-editor-client-transport",
|
|
4224
|
+
description: "Optional messages the web editor host sends to the editor."
|
|
4225
|
+
}, { message: notificationType(object({ message: zJsonValue })) });
|
|
4226
|
+
/** Methods the editor exposes to a presenting host. */
|
|
4227
|
+
const webEditorPresentationInterface = defineInterface({
|
|
4228
|
+
id: "web-editor-presentation",
|
|
4229
|
+
description: "How the embedding host currently presents the editor."
|
|
4230
|
+
}, {
|
|
4231
|
+
/** Sent once the editor initialized, and whenever the mode changes. */
|
|
4232
|
+
changed: notificationType(object({ mode: zPresentationMode })) });
|
|
4233
|
+
/** Methods a presenting host exposes to the editor. */
|
|
4234
|
+
const webEditorPresentationHostInterface = defineInterface({
|
|
4235
|
+
id: "web-editor-presentation-host",
|
|
4236
|
+
description: "Presentation preferences and actions of an embedded editor."
|
|
4237
|
+
}, {
|
|
4238
|
+
/** Replaces the editor's previous preferences. */
|
|
4239
|
+
setPreferences: notificationType(zPresentationPreferences),
|
|
4240
|
+
/** Asks the host to leave full view, for example when the user presses Escape. */
|
|
4241
|
+
exitFullView: notificationType(object({}))
|
|
4242
|
+
});
|
|
4188
4243
|
/** Per-scope registration: `registered` (toolbar button) and `isDefault` (auto-open). */
|
|
4189
4244
|
const zScopeRegistration = object({
|
|
4190
4245
|
registered: boolean(),
|
|
@@ -4260,7 +4315,21 @@ const vscodeAppHostInterface = defineInterface({
|
|
|
4260
4315
|
workspace: zScopeRegistration,
|
|
4261
4316
|
hasWorkspace: boolean(),
|
|
4262
4317
|
changed: boolean()
|
|
4263
|
-
}))
|
|
4318
|
+
})),
|
|
4319
|
+
/**
|
|
4320
|
+
* The view state of this editor tab, such as scroll positions or
|
|
4321
|
+
* selections, as last set by {@link setViewState}. `value` is omitted
|
|
4322
|
+
* when none is set. VS Code restores it when it restores the tab (for
|
|
4323
|
+
* example after a window reload), but a newly opened tab starts
|
|
4324
|
+
* without one. Only the top-level app of a tab has view state.
|
|
4325
|
+
*/
|
|
4326
|
+
getViewState: requestType(object({}), object({ value: zJsonValue.optional() })),
|
|
4327
|
+
/**
|
|
4328
|
+
* Replace this editor tab's view state with a JSON value. The host
|
|
4329
|
+
* rejects values too large to persist with the tab, and calls from
|
|
4330
|
+
* embedded apps.
|
|
4331
|
+
*/
|
|
4332
|
+
setViewState: requestType(object({ value: zJsonValue }), object({}))
|
|
4264
4333
|
});
|
|
4265
4334
|
/** Host-to-parent notifications for loaded child runtime changes. */
|
|
4266
4335
|
const vscodeAppEmbeddingEventsInterface = defineInterface({
|
|
@@ -4382,22 +4451,33 @@ var Emitter = class {
|
|
|
4382
4451
|
var WebEditorHost = class {
|
|
4383
4452
|
_connection;
|
|
4384
4453
|
_editor;
|
|
4454
|
+
_clientTransport;
|
|
4455
|
+
_presentation;
|
|
4385
4456
|
_contentType;
|
|
4386
4457
|
_jsonFormat;
|
|
4387
4458
|
_onError;
|
|
4388
4459
|
_capabilities;
|
|
4460
|
+
_hostTransportSubscription;
|
|
4389
4461
|
_text;
|
|
4390
4462
|
_readOnly;
|
|
4463
|
+
_presentationMode;
|
|
4391
4464
|
_serverRevision = 0;
|
|
4392
4465
|
_acknowledgedClientRevision = 0;
|
|
4393
4466
|
_editorInitialized = false;
|
|
4394
4467
|
_editorCapabilities;
|
|
4468
|
+
_pendingHostTransportMessages = [];
|
|
4395
4469
|
_onDidChangeText = new Emitter();
|
|
4396
4470
|
onDidChangeText = this._onDidChangeText.event;
|
|
4397
4471
|
_onDidInitialize = new Emitter();
|
|
4398
4472
|
onDidInitialize = this._onDidInitialize.event;
|
|
4399
4473
|
_onDidReportSize = new Emitter();
|
|
4400
4474
|
onDidReportSize = this._onDidReportSize.event;
|
|
4475
|
+
_onDidSetPresentationPreferences = new Emitter();
|
|
4476
|
+
/** The editor replaced its presentation preferences. Only fires with `supportsPresentation`. */
|
|
4477
|
+
onDidSetPresentationPreferences = this._onDidSetPresentationPreferences.event;
|
|
4478
|
+
_onDidRequestExitFullView = new Emitter();
|
|
4479
|
+
/** The editor asked to leave full view. Only fires with `supportsPresentation`. */
|
|
4480
|
+
onDidRequestExitFullView = this._onDidRequestExitFullView.event;
|
|
4401
4481
|
constructor(options) {
|
|
4402
4482
|
this._connection = options.connection;
|
|
4403
4483
|
this._contentType = options.contentType ?? "text";
|
|
@@ -4405,8 +4485,14 @@ var WebEditorHost = class {
|
|
|
4405
4485
|
this._readOnly = options.readOnly ?? false;
|
|
4406
4486
|
this._jsonFormat = options.jsonFormat ?? {};
|
|
4407
4487
|
this._onError = options.onError ?? ((m, d) => console.error("WebEditorHost:", m, d));
|
|
4408
|
-
this._capabilities =
|
|
4488
|
+
this._capabilities = {
|
|
4489
|
+
...options.capabilities ?? { supportsForceUpdate: true },
|
|
4490
|
+
supportsHostTransport: options.hostTransport ? true : void 0,
|
|
4491
|
+
supportsPresentation: options.supportsPresentation ? true : void 0
|
|
4492
|
+
};
|
|
4409
4493
|
this._editor = this._connection.get(webEditorInterface);
|
|
4494
|
+
this._clientTransport = this._connection.get(webEditorClientTransportInterface);
|
|
4495
|
+
this._presentation = this._connection.get(webEditorPresentationInterface);
|
|
4410
4496
|
this._connection.register(webEditorHostInterface, {
|
|
4411
4497
|
initialized: (params) => {
|
|
4412
4498
|
if (params.contentType !== this._contentType) this._onError(`Editor contentType "${params.contentType}" does not match host "${this._contentType}"`);
|
|
@@ -4415,6 +4501,8 @@ var WebEditorHost = class {
|
|
|
4415
4501
|
this._serverRevision = 0;
|
|
4416
4502
|
this._acknowledgedClientRevision = 0;
|
|
4417
4503
|
this._pushFullUpdate();
|
|
4504
|
+
for (const message of this._pendingHostTransportMessages.splice(0)) this._clientTransport.message({ message });
|
|
4505
|
+
this._pushPresentationMode();
|
|
4418
4506
|
this._onDidInitialize.fire({ capabilities: params.capabilities });
|
|
4419
4507
|
return {
|
|
4420
4508
|
protocolVersion: "web-editor-host/0.12",
|
|
@@ -4459,6 +4547,17 @@ var WebEditorHost = class {
|
|
|
4459
4547
|
this._onDidReportSize.fire({ height: params.height });
|
|
4460
4548
|
}
|
|
4461
4549
|
});
|
|
4550
|
+
if (options.supportsPresentation) this._connection.register(webEditorPresentationHostInterface, {
|
|
4551
|
+
setPreferences: (preferences) => this._onDidSetPresentationPreferences.fire(preferences),
|
|
4552
|
+
exitFullView: () => this._onDidRequestExitFullView.fire()
|
|
4553
|
+
});
|
|
4554
|
+
if (options.hostTransport) {
|
|
4555
|
+
this._connection.register(webEditorHostTransportInterface, { message: ({ message }) => options.hostTransport.sendMessage(message) });
|
|
4556
|
+
this._hostTransportSubscription = options.hostTransport.onMessage((message) => {
|
|
4557
|
+
if (this._editorInitialized) this._clientTransport.message({ message });
|
|
4558
|
+
else this._pendingHostTransportMessages.push(message);
|
|
4559
|
+
});
|
|
4560
|
+
}
|
|
4462
4561
|
}
|
|
4463
4562
|
/** The text the host believes the document currently holds. */
|
|
4464
4563
|
getText() {
|
|
@@ -4486,6 +4585,15 @@ var WebEditorHost = class {
|
|
|
4486
4585
|
getReadOnly() {
|
|
4487
4586
|
return this._readOnly;
|
|
4488
4587
|
}
|
|
4588
|
+
/**
|
|
4589
|
+
* Tell the editor how the host presents it. Sent to editors that support
|
|
4590
|
+
* presentation once they initialized, and again after they reconnect.
|
|
4591
|
+
*/
|
|
4592
|
+
setPresentationMode(mode) {
|
|
4593
|
+
if (this._presentationMode === mode) return;
|
|
4594
|
+
this._presentationMode = mode;
|
|
4595
|
+
this._pushPresentationMode();
|
|
4596
|
+
}
|
|
4489
4597
|
setReadOnly(readOnly) {
|
|
4490
4598
|
if (this._readOnly === readOnly) return;
|
|
4491
4599
|
this._readOnly = readOnly;
|
|
@@ -4516,9 +4624,13 @@ var WebEditorHost = class {
|
|
|
4516
4624
|
});
|
|
4517
4625
|
}
|
|
4518
4626
|
dispose() {
|
|
4627
|
+
this._hostTransportSubscription?.dispose();
|
|
4519
4628
|
this._onDidChangeText.dispose();
|
|
4520
4629
|
this._onDidInitialize.dispose();
|
|
4521
4630
|
this._onDidReportSize.dispose();
|
|
4631
|
+
this._onDidSetPresentationPreferences.dispose();
|
|
4632
|
+
this._onDidRequestExitFullView.dispose();
|
|
4633
|
+
this._pendingHostTransportMessages.length = 0;
|
|
4522
4634
|
this._connection.close();
|
|
4523
4635
|
}
|
|
4524
4636
|
_pushFullUpdate(force) {
|
|
@@ -4546,6 +4658,10 @@ var WebEditorHost = class {
|
|
|
4546
4658
|
acknowledgedClientRevision: this._acknowledgedClientRevision
|
|
4547
4659
|
});
|
|
4548
4660
|
}
|
|
4661
|
+
_pushPresentationMode() {
|
|
4662
|
+
if (!this._editorInitialized || !this._capabilities.supportsPresentation || !this._editorCapabilities?.supportsPresentation || this._presentationMode === void 0) return;
|
|
4663
|
+
this._presentation.changed({ mode: this._presentationMode });
|
|
4664
|
+
}
|
|
4549
4665
|
_acknowledgeAndRestore(clientRevision) {
|
|
4550
4666
|
this._acknowledgedClientRevision = Math.max(this._acknowledgedClientRevision, clientRevision);
|
|
4551
4667
|
this._pushFullUpdate(true);
|
|
@@ -4697,11 +4813,19 @@ var HostConnection = class HostConnection {
|
|
|
4697
4813
|
var WebEditorClient = class WebEditorClient {
|
|
4698
4814
|
_connection;
|
|
4699
4815
|
_host;
|
|
4816
|
+
_hostTransportProxy;
|
|
4817
|
+
_presentationHost;
|
|
4700
4818
|
_onError;
|
|
4819
|
+
_hostTransport;
|
|
4701
4820
|
_content = void 0;
|
|
4702
4821
|
_readOnly = false;
|
|
4703
4822
|
_options = void 0;
|
|
4704
4823
|
_hostCapabilities;
|
|
4824
|
+
_connected = false;
|
|
4825
|
+
_presentationMode;
|
|
4826
|
+
_presentationPreferences;
|
|
4827
|
+
_pendingHostTransportMessages = [];
|
|
4828
|
+
_hostTransportActivated = false;
|
|
4705
4829
|
_clientRevision = 0;
|
|
4706
4830
|
_basedOnServerRevision = 0;
|
|
4707
4831
|
/** Number of un-acked local revisions. While > 0 the editor has pending edits. */
|
|
@@ -4714,6 +4838,10 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4714
4838
|
onDidChangeReadOnly = this._onDidChangeReadOnly.event;
|
|
4715
4839
|
_onDidChangeOptions = new Emitter();
|
|
4716
4840
|
onDidChangeOptions = this._onDidChangeOptions.event;
|
|
4841
|
+
_onDidChangePresentationMode = new Emitter();
|
|
4842
|
+
/** The embedding host changed how it presents this editor. See {@link getPresentationMode}. */
|
|
4843
|
+
onDidChangePresentationMode = this._onDidChangePresentationMode.event;
|
|
4844
|
+
_onDidReceiveHostMessage = new Emitter();
|
|
4717
4845
|
/** Resolves once the host has acknowledged `initialized`. */
|
|
4718
4846
|
onDidConnect;
|
|
4719
4847
|
static async connect(options) {
|
|
@@ -4725,6 +4853,8 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4725
4853
|
this._connection = resolveConnection(options.connection);
|
|
4726
4854
|
this._onError = options.onError ?? ((m, d) => console.error("WebEditorClient:", m, d));
|
|
4727
4855
|
this._host = this._connection.get(webEditorHostInterface);
|
|
4856
|
+
this._hostTransportProxy = this._connection.get(webEditorHostTransportInterface);
|
|
4857
|
+
this._presentationHost = this._connection.get(webEditorPresentationHostInterface);
|
|
4728
4858
|
this._connection.register(webEditorInterface, {
|
|
4729
4859
|
update: (params) => this._handleUpdate(params),
|
|
4730
4860
|
applyContentEdits: (params) => this._handleApplyContentEdits(params),
|
|
@@ -4732,12 +4862,38 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4732
4862
|
return { schema: options.getContentSchema ? await options.getContentSchema() : null };
|
|
4733
4863
|
}
|
|
4734
4864
|
});
|
|
4865
|
+
this._connection.register(webEditorPresentationInterface, { changed: ({ mode }) => {
|
|
4866
|
+
if (mode === this._presentationMode) return;
|
|
4867
|
+
this._presentationMode = mode;
|
|
4868
|
+
this._onDidChangePresentationMode.fire({ mode });
|
|
4869
|
+
} });
|
|
4870
|
+
this._connection.register(webEditorClientTransportInterface, { message: ({ message }) => {
|
|
4871
|
+
if (this._hostTransportActivated) this._onDidReceiveHostMessage.fire(message);
|
|
4872
|
+
else this._pendingHostTransportMessages.push(message);
|
|
4873
|
+
} });
|
|
4735
4874
|
this.onDidConnect = this._host.initialized({
|
|
4736
4875
|
protocolVersion: "web-editor/0.12",
|
|
4737
4876
|
contentType: options.contentType ?? "text",
|
|
4738
|
-
capabilities:
|
|
4877
|
+
capabilities: {
|
|
4878
|
+
...options.capabilities,
|
|
4879
|
+
supportsPresentation: true
|
|
4880
|
+
}
|
|
4739
4881
|
}).then((r) => {
|
|
4740
4882
|
this._hostCapabilities = r.capabilities;
|
|
4883
|
+
this._connected = true;
|
|
4884
|
+
if (this._presentationPreferences) this.setPresentationPreferences(this._presentationPreferences);
|
|
4885
|
+
if (r.capabilities?.supportsHostTransport) this._hostTransport = {
|
|
4886
|
+
onMessage: (listener) => {
|
|
4887
|
+
const disposable = this._onDidReceiveHostMessage.event(listener);
|
|
4888
|
+
if (!this._hostTransportActivated) {
|
|
4889
|
+
this._hostTransportActivated = true;
|
|
4890
|
+
for (const message of this._pendingHostTransportMessages.splice(0)) listener(message);
|
|
4891
|
+
}
|
|
4892
|
+
return disposable;
|
|
4893
|
+
},
|
|
4894
|
+
sendMessage: (message) => this._hostTransportProxy.message({ message })
|
|
4895
|
+
};
|
|
4896
|
+
else this._pendingHostTransportMessages.length = 0;
|
|
4741
4897
|
return { capabilities: r.capabilities };
|
|
4742
4898
|
});
|
|
4743
4899
|
}
|
|
@@ -4749,6 +4905,10 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4749
4905
|
get connection() {
|
|
4750
4906
|
return this._connection;
|
|
4751
4907
|
}
|
|
4908
|
+
/** Optional notification transport supplied by the web editor host. */
|
|
4909
|
+
get hostTransport() {
|
|
4910
|
+
return this._hostTransport;
|
|
4911
|
+
}
|
|
4752
4912
|
getContent() {
|
|
4753
4913
|
return this._content;
|
|
4754
4914
|
}
|
|
@@ -4786,17 +4946,41 @@ var WebEditorClient = class WebEditorClient {
|
|
|
4786
4946
|
});
|
|
4787
4947
|
}
|
|
4788
4948
|
/**
|
|
4789
|
-
* Report the editor's
|
|
4790
|
-
*
|
|
4949
|
+
* Report the editor's preferred content height (px): the height it needs to
|
|
4950
|
+
* show its content without scrolling, independent of the frame's current
|
|
4951
|
+
* height. A host embedding this editor in an iframe sizes the frame to it.
|
|
4791
4952
|
*/
|
|
4792
4953
|
reportSize(height) {
|
|
4793
4954
|
this._host.reportSize({ height });
|
|
4794
4955
|
}
|
|
4956
|
+
/**
|
|
4957
|
+
* How an embedding host currently presents this editor, or `undefined` when
|
|
4958
|
+
* the host does not present it inline (for example a standalone editor).
|
|
4959
|
+
*/
|
|
4960
|
+
getPresentationMode() {
|
|
4961
|
+
return this._presentationMode;
|
|
4962
|
+
}
|
|
4963
|
+
/**
|
|
4964
|
+
* Ask a presenting host for presentation controls (resize grips, full view).
|
|
4965
|
+
* Replaces earlier preferences; sent once connected, and ignored by hosts
|
|
4966
|
+
* that do not present the editor inline.
|
|
4967
|
+
*/
|
|
4968
|
+
setPresentationPreferences(preferences) {
|
|
4969
|
+
this._presentationPreferences = preferences;
|
|
4970
|
+
if (this._connected && this._hostCapabilities?.supportsPresentation) this._presentationHost.setPreferences(preferences);
|
|
4971
|
+
}
|
|
4972
|
+
/** Ask a presenting host to leave full view. */
|
|
4973
|
+
exitFullView() {
|
|
4974
|
+
if (this._connected && this._hostCapabilities?.supportsPresentation) this._presentationHost.exitFullView({});
|
|
4975
|
+
}
|
|
4795
4976
|
dispose() {
|
|
4796
4977
|
this._onDidChangeContent.dispose();
|
|
4797
4978
|
this._onDidApplyHostEdits.dispose();
|
|
4798
4979
|
this._onDidChangeReadOnly.dispose();
|
|
4799
4980
|
this._onDidChangeOptions.dispose();
|
|
4981
|
+
this._onDidChangePresentationMode.dispose();
|
|
4982
|
+
this._onDidReceiveHostMessage.dispose();
|
|
4983
|
+
this._pendingHostTransportMessages.length = 0;
|
|
4800
4984
|
this._connection.close();
|
|
4801
4985
|
}
|
|
4802
4986
|
_handleUpdate(params) {
|
|
@@ -5045,8 +5229,25 @@ var VsCodeAppHostClient = class {
|
|
|
5045
5229
|
dismissable: options?.dismissable
|
|
5046
5230
|
});
|
|
5047
5231
|
}
|
|
5232
|
+
/**
|
|
5233
|
+
* This editor tab's view state, or `undefined` when none is set. VS Code
|
|
5234
|
+
* restores it with the tab (for example after a window reload); a newly
|
|
5235
|
+
* opened tab starts without one. Validate it like any other persisted
|
|
5236
|
+
* input, since it may come from an older version of the app.
|
|
5237
|
+
*/
|
|
5238
|
+
async getViewState() {
|
|
5239
|
+
return (await this._host.getViewState({})).value;
|
|
5240
|
+
}
|
|
5241
|
+
/**
|
|
5242
|
+
* Replace this editor tab's view state with a JSON value, for example
|
|
5243
|
+
* scroll positions or selections. Use per-app storage for state shared by
|
|
5244
|
+
* every tab. Rejects for values too large to persist and in embedded apps.
|
|
5245
|
+
*/
|
|
5246
|
+
async setViewState(value) {
|
|
5247
|
+
await this._host.setViewState({ value });
|
|
5248
|
+
}
|
|
5048
5249
|
};
|
|
5049
5250
|
//#endregion
|
|
5050
|
-
export { EmbeddedAppHandle, VsCodeAppHostClient, WebEditorClient, WebEditorHost, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorHostInterface, webEditorInterface };
|
|
5251
|
+
export { EmbeddedAppHandle, VsCodeAppHostClient, WebEditorClient, WebEditorHost, WindowMessageTransport, applyContentEdits, applyTextEdits, createWindowParentConnection, decodeFromEditor, encodeForEditor, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface, webEditorPresentationHostInterface, webEditorPresentationInterface };
|
|
5051
5252
|
|
|
5052
5253
|
//# sourceMappingURL=index.js.map
|