@vscode/web-editors 0.0.2-13 → 0.0.2-130

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 CHANGED
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ import { i as IDisposable, n as SyncedTextDocument, r as Event, t as DocumentTextEdit } from "./chunks/syncedTextDocument-EBcq_UIM.js";
5
6
  import { HubRpcConnection, InterfaceClient, InterfaceDefinition, MemberMap } from "@vscode/hubrpc";
6
7
  import { MessageEndpoint, MessageLikeEvent, WindowMessageTransport } from "@vscode/hubrpc/web";
7
8
  import { HubAccessDuration, HubAccessRequest, HubAccessResult } from "@vscode/hubrpc/hub/common";
@@ -2140,14 +2141,25 @@ interface ZodReadonly<T extends SomeType = $ZodType> extends _ZodType<$ZodReadon
2140
2141
  declare const ZodReadonly: $constructor<ZodReadonly>;
2141
2142
  //#endregion
2142
2143
  //#region src/protocol.d.ts
2144
+ /**
2145
+ * The concurrency control both sides use when they announce it: concurrent
2146
+ * edits are transformed against each other instead of one side's being
2147
+ * dropped. See `OtPeer`.
2148
+ */
2149
+ declare const OT_EDIT_TRANSFORM = "ot/1";
2143
2150
  declare const zEditorCapabilities: ZodObject<{
2144
2151
  supportsContentEdits: ZodOptional<ZodBoolean>;
2145
2152
  supportsOptions: ZodOptional<ZodBoolean>;
2153
+ supportsPresentation: ZodOptional<ZodBoolean>;
2154
+ editTransforms: ZodOptional<ZodArray<ZodString>>;
2146
2155
  }, $strip>;
2147
2156
  declare const zHostCapabilities: ZodObject<{
2148
2157
  supportsContentEdits: ZodOptional<ZodBoolean>;
2149
2158
  supportsOptions: ZodOptional<ZodBoolean>;
2150
2159
  supportsForceUpdate: ZodOptional<ZodBoolean>;
2160
+ supportsHostTransport: ZodOptional<ZodBoolean>;
2161
+ supportsPresentation: ZodOptional<ZodBoolean>;
2162
+ editTransform: ZodOptional<ZodString>;
2151
2163
  }, $strip>;
2152
2164
  declare const zTextEdit: ZodObject<{
2153
2165
  offset: ZodNumber;
@@ -2174,15 +2186,51 @@ declare const zWebEditorUpdate: ZodObject<{
2174
2186
  serverRevision: ZodOptional<ZodNumber>;
2175
2187
  acknowledgedClientRevision: ZodOptional<ZodNumber>;
2176
2188
  force: ZodOptional<ZodBoolean>;
2189
+ editTransform: ZodOptional<ZodString>;
2190
+ }, $strip>;
2191
+ /** How an embedding host currently presents the editor. */
2192
+ declare const zPresentationMode: ZodEnum<{
2193
+ inline: "inline";
2194
+ "full-width": "full-width";
2195
+ "full-view": "full-view";
2196
+ }>;
2197
+ /**
2198
+ * Presentation controls the editor asks its embedding host for. The host's own
2199
+ * configuration takes precedence over these preferences.
2200
+ */
2201
+ declare const zPresentationPreferences: ZodObject<{
2202
+ resizable: ZodOptional<ZodBoolean>;
2203
+ fullWidth: ZodOptional<ZodBoolean>;
2204
+ fullView: ZodOptional<ZodBoolean>;
2205
+ minHeight: ZodOptional<ZodNumber>;
2206
+ maxAutomaticHeight: ZodOptional<ZodNumber>;
2177
2207
  }, $strip>;
2178
2208
  type ContentEdit = output<typeof zContentEdit>;
2179
2209
  type TextEdit = output<typeof zTextEdit>;
2180
2210
  type EditorCapabilities = output<typeof zEditorCapabilities>;
2181
2211
  type HostCapabilities = output<typeof zHostCapabilities>;
2182
2212
  type WebEditorUpdate = output<typeof zWebEditorUpdate>;
2213
+ type PresentationMode = output<typeof zPresentationMode>;
2214
+ type PresentationPreferences = output<typeof zPresentationPreferences>;
2183
2215
  type ContentType = "text" | "json";
2216
+ /**
2217
+ * Identifies a state of the content that the host and the editor share: the
2218
+ * host's and the editor's edits integrated into it. Send it along with
2219
+ * offsets into the content, so that the other side can map them into its
2220
+ * current content (`mapOffset` on `WebEditorHost` and `WebEditorClient`).
2221
+ */
2222
+ interface ContentVersion {
2223
+ readonly serverRevision: number;
2224
+ readonly clientRevision: number;
2225
+ }
2184
2226
  declare const webEditorHostInterface: any;
2185
2227
  declare const webEditorInterface: any;
2228
+ declare const webEditorHostTransportInterface: any;
2229
+ declare const webEditorClientTransportInterface: any;
2230
+ /** Methods the editor exposes to a presenting host. */
2231
+ declare const webEditorPresentationInterface: any;
2232
+ /** Methods a presenting host exposes to the editor. */
2233
+ declare const webEditorPresentationHostInterface: any;
2186
2234
  declare const zEmbeddedAppDescriptor: ZodObject<{
2187
2235
  handleId: ZodString;
2188
2236
  appId: ZodString;
@@ -2205,6 +2253,10 @@ declare const vscodeAppEmbeddingEventsInterface: any;
2205
2253
  type WebEditorHostProxy = InterfaceClient<typeof webEditorHostInterface>;
2206
2254
  /** Typed proxy used by the host to invoke editor methods. */
2207
2255
  type WebEditorProxy = InterfaceClient<typeof webEditorInterface>;
2256
+ type WebEditorHostTransportProxy = InterfaceClient<typeof webEditorHostTransportInterface>;
2257
+ type WebEditorClientTransportProxy = InterfaceClient<typeof webEditorClientTransportInterface>;
2258
+ type WebEditorPresentationProxy = InterfaceClient<typeof webEditorPresentationInterface>;
2259
+ type WebEditorPresentationHostProxy = InterfaceClient<typeof webEditorPresentationHostInterface>;
2208
2260
  /** Typed proxy used by an app to invoke `vscode-app-host` methods. */
2209
2261
  type VsCodeAppHostProxy = InterfaceClient<typeof vscodeAppHostInterface>;
2210
2262
  type VsCodeAppEmbeddingEventsProxy = InterfaceClient<typeof vscodeAppEmbeddingEventsInterface>;
@@ -2273,12 +2325,15 @@ declare function encodeForEditor(text: string, contentType: ContentType): JsonVa
2273
2325
  */
2274
2326
  declare function decodeFromEditor(value: JsonValue, contentType: ContentType, options?: JsonFormatOptions): string;
2275
2327
  //#endregion
2276
- //#region src/utils/event.d.ts
2277
- interface IDisposable {
2278
- dispose(): void;
2328
+ //#region src/hostTransport.d.ts
2329
+ /**
2330
+ * Optional message transport between a web editor and its host.
2331
+ */
2332
+ interface HostTransport {
2333
+ readonly onMessage: Event<JsonValue>;
2334
+ /** Sends a notification to the host. */
2335
+ sendMessage(message: JsonValue): void;
2279
2336
  }
2280
- type EventListener<T> = (event: T) => void;
2281
- type Event<T> = (listener: EventListener<T>) => IDisposable;
2282
2337
  //#endregion
2283
2338
  //#region src/host/WebEditorHost.d.ts
2284
2339
  interface WebEditorHostOptions {
@@ -2302,6 +2357,14 @@ interface WebEditorHostOptions {
2302
2357
  jsonFormat?: JsonFormatOptions;
2303
2358
  /** Host capabilities advertised on `initialized`. */
2304
2359
  capabilities?: HostCapabilities;
2360
+ /** Optional message transport to expose to the editor. */
2361
+ hostTransport?: HostTransport;
2362
+ /**
2363
+ * The host presents the editor inline (for example as a block in a document)
2364
+ * and exchanges presentation state with editors that support it: see
2365
+ * {@link WebEditorHost.setPresentationMode} and the presentation events.
2366
+ */
2367
+ supportsPresentation?: boolean;
2305
2368
  /** Called when the editor sends malformed input. Defaults to `console.error`. */
2306
2369
  onError?: (message: string, detail?: unknown) => void;
2307
2370
  }
@@ -2309,25 +2372,40 @@ interface WebEditorHostOptions {
2309
2372
  * Host-side façade for the web-editor v0.12 protocol.
2310
2373
  *
2311
2374
  * Owns the canonical text content. Translates between text/JSON form and the
2312
- * structural edits exchanged with the editor. Maintains the revision pair
2313
- * required by the client-authority conflict policy.
2375
+ * structural edits exchanged with the editor.
2376
+ *
2377
+ * Concurrent edits from both sides are merged with operational transformation
2378
+ * when the editor supports it ({@link OT_EDIT_TRANSFORM}). Otherwise the host
2379
+ * maintains the revision pair required by the client-authority conflict
2380
+ * policy, under which conflicting edits are dropped.
2314
2381
  */
2315
2382
  declare class WebEditorHost implements IDisposable {
2316
2383
  private readonly _connection;
2317
2384
  private readonly _editor;
2385
+ private readonly _clientTransport;
2386
+ private readonly _presentation;
2318
2387
  private readonly _contentType;
2319
2388
  private readonly _jsonFormat;
2320
2389
  private readonly _onError;
2321
2390
  private readonly _capabilities;
2391
+ private readonly _hostTransportSubscription;
2322
2392
  private _text;
2323
2393
  private _readOnly;
2394
+ private _presentationMode;
2395
+ /** Set while connected to an editor that merges concurrent edits. */
2396
+ private _transform;
2397
+ /** Client-authority policy only. */
2324
2398
  private _serverRevision;
2399
+ /** Client-authority policy only. */
2325
2400
  private _acknowledgedClientRevision;
2326
2401
  private _editorInitialized;
2327
2402
  private _editorCapabilities;
2403
+ private readonly _pendingHostTransportMessages;
2328
2404
  private readonly _onDidChangeText;
2405
+ /** The editor changed the content. `edits` apply to the previous content, in the editor's form. */
2329
2406
  readonly onDidChangeText: Event<{
2330
2407
  text: string;
2408
+ edits: readonly ContentEdit[];
2331
2409
  }>;
2332
2410
  private readonly _onDidInitialize;
2333
2411
  readonly onDidInitialize: Event<{
@@ -2337,12 +2415,33 @@ declare class WebEditorHost implements IDisposable {
2337
2415
  readonly onDidReportSize: Event<{
2338
2416
  height: number;
2339
2417
  }>;
2418
+ private readonly _onDidSetPresentationPreferences;
2419
+ /** The editor replaced its presentation preferences. Only fires with `supportsPresentation`. */
2420
+ readonly onDidSetPresentationPreferences: Event<PresentationPreferences>;
2421
+ private readonly _onDidRequestExitFullView;
2422
+ /** The editor asked to leave full view. Only fires with `supportsPresentation`. */
2423
+ readonly onDidRequestExitFullView: Event<void>;
2340
2424
  constructor(options: WebEditorHostOptions);
2341
2425
  /** The text the host believes the document currently holds. */
2342
2426
  getText(): string;
2427
+ /** The current content's version, to send along with offsets into it. */
2428
+ get version(): ContentVersion;
2343
2429
  /**
2344
- * Push a new full text to the editor. Sent as a `replace` at the document
2345
- * root. If `force`, the editor must adopt it even with pending local edits.
2430
+ * Maps an offset into the string at `path`, which the editor computed on
2431
+ * its content at `version`, into the current content. Call it when the
2432
+ * editor's message arrives: its earlier edits are integrated by then.
2433
+ *
2434
+ * @returns `undefined` if the offset cannot be mapped, for example because
2435
+ * the string was replaced or the content was reset since.
2436
+ */
2437
+ mapOffset(version: ContentVersion, path: readonly string[], offset: number, assoc?: "before" | "after"): number | undefined;
2438
+ /**
2439
+ * Change the text the editor shows.
2440
+ *
2441
+ * When the editor merges concurrent edits, the change is sent as edits
2442
+ * that merge with the editor's unsent edits. Otherwise, and with `force`,
2443
+ * the full text is sent. If `force`, the editor must adopt it even with
2444
+ * pending local edits, which are then discarded.
2346
2445
  */
2347
2446
  setText(text: string, opts?: {
2348
2447
  force?: boolean;
@@ -2354,15 +2453,32 @@ declare class WebEditorHost implements IDisposable {
2354
2453
  */
2355
2454
  reuse(text: string, readOnly: boolean): void;
2356
2455
  getReadOnly(): boolean;
2456
+ /**
2457
+ * Tell the editor how the host presents it. Sent to editors that support
2458
+ * presentation once they initialized, and again after they reconnect.
2459
+ */
2460
+ setPresentationMode(mode: PresentationMode): void;
2357
2461
  setReadOnly(readOnly: boolean): void;
2358
2462
  /**
2359
- * Push fine-grained edits to the editor.
2360
- * The host is responsible for keeping its own `_text` consistent with these edits.
2463
+ * Change the text by fine-grained edits, which are pushed to the editor.
2464
+ * An editor that initializes later receives the changed text.
2361
2465
  */
2362
2466
  applyEdits(edits: readonly ContentEdit[]): void;
2363
2467
  dispose(): void;
2468
+ private _applyTransformedEditorEdit;
2469
+ /** The text after the editor's `edits`, or `undefined` after reporting why they do not apply. */
2470
+ private _applyEditorEdits;
2471
+ /** Edits from `oldText` to `newText` in the editor's form, or `undefined` if either cannot be encoded. */
2472
+ private _diff;
2473
+ private _sendHostEdits;
2364
2474
  private _pushFullUpdate;
2475
+ /**
2476
+ * Sends the full content, which replaces the editor's. Editor edits made
2477
+ * before the editor receives it are discarded on both sides.
2478
+ */
2479
+ private _resetEditor;
2365
2480
  private _pushAcknowledgement;
2481
+ private _pushPresentationMode;
2366
2482
  private _acknowledgeAndRestore;
2367
2483
  }
2368
2484
  //#endregion
@@ -2459,25 +2575,46 @@ interface WebEditorClientState {
2459
2575
  * Calls `host.initialized` immediately, then exposes the current content and
2460
2576
  * read-only flag as observable events. Local edits made through {@link applyEdits}
2461
2577
  * are sent to the host with monotonically increasing client revisions.
2578
+ *
2579
+ * When the host supports it ({@link OT_EDIT_TRANSFORM}), host edits that
2580
+ * arrive while local edits are unacknowledged are transformed against them,
2581
+ * so neither side's edits are lost. Otherwise such host changes are dropped
2582
+ * (client-authority policy).
2462
2583
  */
2463
2584
  declare class WebEditorClient implements IDisposable {
2464
2585
  private readonly _connection;
2465
2586
  private readonly _host;
2587
+ private readonly _hostTransportProxy;
2588
+ private readonly _presentationHost;
2466
2589
  private readonly _onError;
2590
+ private _hostTransport;
2467
2591
  private _content;
2468
2592
  private _readOnly;
2469
2593
  private _options;
2470
2594
  private _hostCapabilities;
2471
- private _clientRevision;
2595
+ private _connected;
2596
+ private _presentationMode;
2597
+ private _presentationPreferences;
2598
+ private readonly _pendingHostTransportMessages;
2599
+ private _hostTransportActivated;
2600
+ /** Local edits and their revisions; its pending edits are those the host has not acknowledged. */
2601
+ private readonly _edits;
2602
+ /** Whether the host transforms concurrent edits, as announced with its first content. */
2603
+ private _transform;
2604
+ /** Client-authority policy only. */
2472
2605
  private _basedOnServerRevision;
2473
- /** Number of un-acked local revisions. While > 0 the editor has pending edits. */
2474
- private _pendingLocalEdits;
2475
2606
  private readonly _onDidChangeContent;
2607
+ /**
2608
+ * The content changed: by a local edit, by host edits (after
2609
+ * {@link onDidApplyHostEdits}) or replaced by the host. Listeners must
2610
+ * tolerate content they already show.
2611
+ */
2476
2612
  readonly onDidChangeContent: Event<{
2477
2613
  content: JsonValue;
2478
2614
  force: boolean;
2479
2615
  }>;
2480
2616
  private readonly _onDidApplyHostEdits;
2617
+ /** Host edits were applied; `edits` are relative to the previous content, after transformation against local edits. */
2481
2618
  readonly onDidApplyHostEdits: Event<{
2482
2619
  edits: ContentEdit[];
2483
2620
  content: JsonValue;
@@ -2490,6 +2627,12 @@ declare class WebEditorClient implements IDisposable {
2490
2627
  readonly onDidChangeOptions: Event<{
2491
2628
  options: JsonValue;
2492
2629
  }>;
2630
+ private readonly _onDidChangePresentationMode;
2631
+ /** The embedding host changed how it presents this editor. See {@link getPresentationMode}. */
2632
+ readonly onDidChangePresentationMode: Event<{
2633
+ mode: PresentationMode;
2634
+ }>;
2635
+ private readonly _onDidReceiveHostMessage;
2493
2636
  /** Resolves once the host has acknowledged `initialized`. */
2494
2637
  readonly onDidConnect: Promise<{
2495
2638
  capabilities: HostCapabilities | undefined;
@@ -2502,7 +2645,22 @@ declare class WebEditorClient implements IDisposable {
2502
2645
  * second one.
2503
2646
  */
2504
2647
  get connection(): HubRpcConnection;
2648
+ /** Optional notification transport supplied by the web editor host. */
2649
+ get hostTransport(): HostTransport | undefined;
2505
2650
  getContent(): JsonValue;
2651
+ /** The current content's version, to send along with offsets into it. */
2652
+ get version(): ContentVersion;
2653
+ /**
2654
+ * Maps an offset into the string at `path`, which the host computed on its
2655
+ * content at `version`, into the current content. Call it when the host's
2656
+ * message arrives.
2657
+ *
2658
+ * @returns `undefined` if the offset cannot be mapped, for example because
2659
+ * host edits arrived since or the string was replaced.
2660
+ */
2661
+ mapOffset(version: ContentVersion, path: readonly string[], offset: number, assoc?: "before" | "after"): number | undefined;
2662
+ /** The host revision the content is based on. */
2663
+ private get _serverRevision();
2506
2664
  getReadOnly(): boolean;
2507
2665
  getOptions(): JsonValue;
2508
2666
  getHostCapabilities(): HostCapabilities | undefined;
@@ -2512,13 +2670,28 @@ declare class WebEditorClient implements IDisposable {
2512
2670
  */
2513
2671
  applyEdits(edits: readonly ContentEdit[]): void;
2514
2672
  /**
2515
- * Report the editor's current laid-out content height (px) to the host.
2516
- * A host embedding this editor in an iframe uses it to size the frame.
2673
+ * Report the editor's preferred content height (px): the height it needs to
2674
+ * show its content without scrolling, independent of the frame's current
2675
+ * height. A host embedding this editor in an iframe sizes the frame to it.
2517
2676
  */
2518
2677
  reportSize(height: number): void;
2678
+ /**
2679
+ * How an embedding host currently presents this editor, or `undefined` when
2680
+ * the host does not present it inline (for example a standalone editor).
2681
+ */
2682
+ getPresentationMode(): PresentationMode | undefined;
2683
+ /**
2684
+ * Ask a presenting host for presentation controls (resize grips, full view).
2685
+ * Replaces earlier preferences; sent once connected, and ignored by hosts
2686
+ * that do not present the editor inline.
2687
+ */
2688
+ setPresentationPreferences(preferences: PresentationPreferences): void;
2689
+ /** Ask a presenting host to leave full view. */
2690
+ exitFullView(): void;
2519
2691
  dispose(): void;
2520
2692
  private _handleUpdate;
2521
2693
  private _handleApplyContentEdits;
2694
+ private _applyTransformedHostEdits;
2522
2695
  private _acknowledge;
2523
2696
  }
2524
2697
  //#endregion
@@ -2654,7 +2827,310 @@ declare class VsCodeAppHostClient {
2654
2827
  configureEditorAssociation(extension: string, options?: {
2655
2828
  dismissable?: boolean;
2656
2829
  }): Promise<EditorAssociationResult>;
2830
+ /**
2831
+ * This editor tab's view state, or `undefined` when none is set. VS Code
2832
+ * restores it with the tab (for example after a window reload); a newly
2833
+ * opened tab starts without one. Validate it like any other persisted
2834
+ * input, since it may come from an older version of the app.
2835
+ */
2836
+ getViewState(): Promise<unknown>;
2837
+ /**
2838
+ * Replace this editor tab's view state with a JSON value, for example
2839
+ * scroll positions or selections. Use per-app storage for state shared by
2840
+ * every tab. Rejects for values too large to persist and in embedded apps.
2841
+ */
2842
+ setViewState(value: unknown): Promise<void>;
2843
+ }
2844
+ //#endregion
2845
+ //#region src/sync/otPeer.d.ts
2846
+ /**
2847
+ * How to transform two concurrent operations of type `TOp`.
2848
+ *
2849
+ * `transform(winner, loser)` returns `[winner', loser']` such that applying
2850
+ * `loser` then `winner'` gives the same state as applying `winner` then
2851
+ * `loser'`. Where both conflict, `winner` takes precedence.
2852
+ */
2853
+ interface OtType<TOp> {
2854
+ transform(winner: TOp, loser: TOp): readonly [TOp, TOp];
2855
+ }
2856
+ /**
2857
+ * One of the two sides of a session that keeps a document in sync between
2858
+ * two parties who both edit it (the Jupiter algorithm behind most operational
2859
+ * transformation systems).
2860
+ *
2861
+ * Each side applies its own operations immediately and sends them along with
2862
+ * how many of the other side's operations it had applied. When an operation
2863
+ * from the other side arrives, it was made without the local operations the
2864
+ * other side had not seen yet. Those pending operations and the incoming one
2865
+ * are transformed against each other: the incoming one is then applied, and
2866
+ * the pending ones now describe how the local state differs from the other
2867
+ * side's. Once both sides have received everything, they hold the same
2868
+ * document, and no operation was dropped.
2869
+ *
2870
+ * The leader's operations take precedence in conflicts. Exactly one side must
2871
+ * be the leader. Messages must arrive in the order they were sent.
2872
+ *
2873
+ * The leader can also start over from a state it sends in full ({@link reset});
2874
+ * the follower's operations that were made before it received that state are
2875
+ * then discarded on both sides.
2876
+ */
2877
+ declare class OtPeer<TOp> {
2878
+ private readonly _type;
2879
+ readonly role: "leader" | "follower";
2880
+ private _localRevision;
2881
+ private _remoteRevision;
2882
+ private _pending;
2883
+ /** Remote operations made before the remote side saw this local revision are discarded. */
2884
+ private _barrier;
2885
+ constructor(_type: OtType<TOp>, role: "leader" | "follower");
2886
+ /** Number of local operations, including resets. */
2887
+ get localRevision(): number;
2888
+ /** Number of remote operations integrated, including discarded ones. */
2889
+ get remoteRevision(): number;
2890
+ /** Local operations the remote side has not acknowledged yet, oldest first. */
2891
+ get pending(): readonly TOp[];
2892
+ /**
2893
+ * The local operations after `revision`, oldest first: how the local state
2894
+ * differs from the state the remote side had when it had integrated
2895
+ * `revision` and everything local before. `undefined` if they are no
2896
+ * longer known, because they were acknowledged since or a reset happened.
2897
+ */
2898
+ operationsAfter(revision: number): readonly TOp[] | undefined;
2899
+ /**
2900
+ * Records an operation already applied to the local state. Send it with
2901
+ * the returned revision and {@link remoteRevision} as the acknowledgement.
2902
+ */
2903
+ local(op: TOp): number;
2904
+ /**
2905
+ * Integrates an operation from the remote side.
2906
+ *
2907
+ * @param revision The remote side's revision after `op`.
2908
+ * @param acknowledgedRevision How many local operations the remote side had integrated when it made `op`.
2909
+ * @returns The operation to apply to the local state, or `undefined` if
2910
+ * `op` was made before the remote side received the latest reset.
2911
+ */
2912
+ remote(op: TOp, revision: number, acknowledgedRevision: number): TOp | undefined;
2913
+ /** The remote side has integrated all local operations up to `revision`. */
2914
+ acknowledge(revision: number): void;
2915
+ /**
2916
+ * Leader only: the local state is about to be sent in full and replaces
2917
+ * whatever the follower has. Returns the revision of the reset.
2918
+ *
2919
+ * @param remoteRevision Treat remote operations up to this revision as
2920
+ * integrated, to recover when the remote side's revisions got out of step.
2921
+ */
2922
+ reset(remoteRevision?: number): number;
2923
+ /**
2924
+ * Follower only: replaces the local state with the leader's full state at
2925
+ * `revision`. Pending local operations are discarded, as the leader
2926
+ * discards them too.
2927
+ */
2928
+ acceptReset(revision: number): void;
2929
+ }
2930
+ //#endregion
2931
+ //#region src/sync/textOperation.d.ts
2932
+ /** {@link OtType} for {@link TextOperation}s. */
2933
+ declare const textOperationOt: OtType<TextOperation>;
2934
+ /**
2935
+ * A change to a string, as a sequence of components that walk the original
2936
+ * string from start to end: keep (`retain`), add (`insert`) or remove
2937
+ * (`delete`) text. Everything after the last component is kept.
2938
+ *
2939
+ * Operations are normalized (see {@link TextOperationBuilder}), so equal
2940
+ * changes have equal components. Their size depends on the number of edited
2941
+ * regions, not on the length of the string.
2942
+ */
2943
+ declare class TextOperation {
2944
+ readonly components: readonly TextComponent[];
2945
+ static get identity(): TextOperation;
2946
+ /** Converts edits that apply one after another, as on the wire, into one operation. */
2947
+ static fromTextEdits(edits: readonly TextEdit[]): TextOperation;
2948
+ /** Use {@link TextOperationBuilder}, which normalizes the components. */
2949
+ constructor(token: typeof normalizedToken, components: readonly TextComponent[]);
2950
+ get isIdentity(): boolean;
2951
+ /** Length of the shortest string this operation applies to. */
2952
+ get baseSpan(): number;
2953
+ apply(text: string): string;
2954
+ /** Edits in ascending order that, applied one after another, have the effect of this operation. */
2955
+ toTextEdits(): TextEdit[];
2956
+ /** The operation that has the effect of this operation followed by `next`. */
2957
+ compose(next: TextOperation): TextOperation;
2958
+ /**
2959
+ * Transforms two operations on the same string so that each applies after
2960
+ * the other and both orders give the same result (`b'(a(s)) === a'(b(s))`).
2961
+ * Where both insert at the same position, `winner`'s text comes first.
2962
+ *
2963
+ * @returns `[winner', loser']`: `winner'` applies after `loser`, `loser'` after `winner`.
2964
+ */
2965
+ static transform(winner: TextOperation, loser: TextOperation): [TextOperation, TextOperation];
2966
+ /**
2967
+ * Where `offset` in the original string ends up after this operation.
2968
+ * An offset inside deleted text maps to where the deletion happened. Text
2969
+ * inserted exactly at `offset` ends up before the result for
2970
+ * `assoc === "after"` and after it for `assoc === "before"`.
2971
+ */
2972
+ mapOffset(offset: number, assoc?: "before" | "after"): number;
2973
+ equals(other: TextOperation): boolean;
2974
+ toString(): string;
2975
+ }
2976
+ type TextComponent = {
2977
+ readonly kind: "retain";
2978
+ readonly length: number;
2979
+ } | {
2980
+ readonly kind: "insert";
2981
+ readonly text: string;
2982
+ } | {
2983
+ readonly kind: "delete";
2984
+ readonly length: number;
2985
+ };
2986
+ declare const normalizedToken: unique symbol;
2987
+ /**
2988
+ * Builds normalized {@link TextOperation}s: no empty components, adjacent
2989
+ * components of the same kind merged, an insert before a delete at the same
2990
+ * position, and no trailing retain.
2991
+ */
2992
+ declare class TextOperationBuilder {
2993
+ private readonly _components;
2994
+ retain(length: number): this;
2995
+ insert(text: string): this;
2996
+ delete(length: number): this;
2997
+ build(): TextOperation;
2998
+ }
2999
+ //#endregion
3000
+ //#region src/sync/textDiff.d.ts
3001
+ /**
3002
+ * An operation that turns `oldText` into `newText` by replacing everything
3003
+ * between their common prefix and suffix. Linear time, so it stays fast for
3004
+ * large texts; separate changes become one replacement of the text between them.
3005
+ *
3006
+ * The replacement never starts or ends between `\r` and `\n`, so that text
3007
+ * inserted concurrently at its edges cannot split a `\r\n` line break.
3008
+ */
3009
+ declare function diffText(oldText: string, newText: string): TextOperation;
3010
+ //#endregion
3011
+ //#region src/sync/contentOperation.d.ts
3012
+ /** {@link OtType} for lists of {@link ContentEdit}s, as exchanged by web editors. */
3013
+ declare const contentEditsOt: OtType<readonly ContentEdit[]>;
3014
+ /**
3015
+ * Transforms two concurrent lists of {@link ContentEdit}s made on the same
3016
+ * content, so that each list applies after the other and both orders give the
3017
+ * same content.
3018
+ *
3019
+ * Edits at unrelated paths do not interact. String edits at the same path are
3020
+ * merged with {@link TextOperation.transform}. A `replace` overrides every
3021
+ * concurrent edit at or below its path; of two replacements at the same path,
3022
+ * `winner`'s is kept.
3023
+ *
3024
+ * @returns `[winner', loser']`: `winner'` applies after `loser`, `loser'` after `winner`.
3025
+ */
3026
+ declare function transformContentEdits(winner: readonly ContentEdit[], loser: readonly ContentEdit[]): [ContentEdit[], ContentEdit[]];
3027
+ /**
3028
+ * Where `offset` in the string at `path` ends up after `edits`, or `undefined`
3029
+ * if the string was replaced. See {@link TextOperation.mapOffset} for `assoc`.
3030
+ */
3031
+ declare function mapContentOffset(edits: readonly ContentEdit[], path: readonly string[], offset: number, assoc?: "before" | "after"): number | undefined;
3032
+ /** Maps `offset` through each list of edits in turn; `undefined` if `operations` is `undefined` or the offset does not survive an edit. */
3033
+ declare function mapThrough(operations: readonly (readonly ContentEdit[])[] | undefined, path: readonly string[], offset: number, assoc?: "before" | "after"): number | undefined;
3034
+ /**
3035
+ * Edits that turn `oldValue` into `newValue`, as fine-grained as possible so
3036
+ * that they merge with concurrent edits: changed strings become string edits,
3037
+ * objects with the same keys and arrays with the same length are compared
3038
+ * member by member, and anything else is replaced.
3039
+ */
3040
+ declare function diffContent(oldValue: JsonValue, newValue: JsonValue, path?: string[]): ContentEdit[];
3041
+ //#endregion
3042
+ //#region src/documentSync/textDocumentSync.d.ts
3043
+ interface TextDocumentSyncOptions {
3044
+ /** Called for failed or rejected writes. Defaults to `console.error`. */
3045
+ onError?: (message: string, detail?: unknown) => void;
3046
+ }
3047
+ /** Options for the {@link WebEditorHost} of a connected editor. */
3048
+ type TextDocumentEditorOptions = Omit<WebEditorHostOptions, "connection" | "initialText" | "onError">;
3049
+ /**
3050
+ * Keeps a web editor's text and a {@link SyncedTextDocument} in sync while
3051
+ * both change.
3052
+ *
3053
+ * The editor text is the document text plus the editor's changes that are not
3054
+ * in the document yet. Editor changes are written one batch at a time. A
3055
+ * document change that is not such a write, for example an undo, a format on
3056
+ * save or another editor's edit, is transformed against the unwritten editor
3057
+ * changes and sent to the editor, so neither side's changes are lost. A write
3058
+ * the document rejects because it changed meanwhile is transformed the same
3059
+ * way and written again. If the document applies a write differently, for
3060
+ * example with its own line breaks, the editor receives the difference.
3061
+ *
3062
+ * Editors connect through a {@link WebEditorHost}, which merges the editor's
3063
+ * unsent edits with the changes sent to it (operational transformation).
3064
+ * Each (re)loaded editor connects anew.
3065
+ */
3066
+ declare class TextDocumentSync implements IDisposable {
3067
+ private readonly _document;
3068
+ private readonly _onError;
3069
+ /** The document text as last seen. */
3070
+ private _documentText;
3071
+ /** {@link _documentText} with {@link _writing} and {@link _unwritten} applied. */
3072
+ private _text;
3073
+ private _revision;
3074
+ private _writing;
3075
+ /**
3076
+ * Document changes seen while {@link _writing} is in flight. They are
3077
+ * settled when it completes: only then is it known whether the first one
3078
+ * is the write.
3079
+ */
3080
+ private readonly _changesDuringWrite;
3081
+ /** Editor changes after {@link _writing} that are not written yet. */
3082
+ private _unwritten;
3083
+ private _host;
3084
+ private _contentType;
3085
+ private readonly _tracked;
3086
+ private readonly _onDidChangeText;
3087
+ /** Fires after every change of {@link text}. */
3088
+ readonly onDidChangeText: Event<void>;
3089
+ private readonly _onDidSettle;
3090
+ private readonly _subscription;
3091
+ private _disposed;
3092
+ constructor(_document: SyncedTextDocument, options?: TextDocumentSyncOptions);
3093
+ /** The editor text: the document text with the editor changes that are not written yet. */
3094
+ get text(): string;
3095
+ /** Changes with every change of {@link text}. */
3096
+ get revision(): number;
3097
+ /** The version to send along with offsets into {@link text}, while an editor is connected. */
3098
+ get version(): ContentVersion | undefined;
3099
+ /**
3100
+ * Connects a (re)loaded editor, which receives the current text. Replaces
3101
+ * the previous editor's host, which is disposed along with its connection.
3102
+ */
3103
+ connect(connection: HubRpcConnection, options?: TextDocumentEditorOptions): WebEditorHost;
3104
+ /**
3105
+ * Follows `offset` in {@link text} through later changes, until disposed.
3106
+ * With `"after"` (the default), text inserted exactly at the offset ends up
3107
+ * before it.
3108
+ */
3109
+ track(offset: number, assoc?: "before" | "after"): TrackedOffset;
3110
+ /**
3111
+ * Tracks an offset into the text that the editor sent along with
3112
+ * `version`; `undefined` if it cannot be mapped. Call it when the editor's
3113
+ * message arrives.
3114
+ */
3115
+ trackFromEditor(version: ContentVersion, offset: number, assoc?: "before" | "after"): TrackedOffset | undefined;
3116
+ /**
3117
+ * Resolves once every editor change is in the document, so that
3118
+ * {@link text} equals the document text. Rejects if the sync is disposed.
3119
+ */
3120
+ drain(): Promise<void>;
3121
+ dispose(): void;
3122
+ private _acceptEditorChange;
3123
+ private _acceptDocumentChange;
3124
+ /** Someone else changed the document: merges the change with the editor changes that are not written yet. */
3125
+ private _acceptExternalChange;
3126
+ private _write;
3127
+ /** Applies a change that comes from the document to {@link text} and sends it to the editor. */
3128
+ private _applyFromDocument;
3129
+ private _applyToText;
3130
+ }
3131
+ interface TrackedOffset extends IDisposable {
3132
+ readonly offset: number;
2657
3133
  }
2658
3134
  //#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 };
3135
+ export { AppContext, type ConnectionInput, ContentEdit, ContentType, ContentVersion, DocumentTextEdit, EditorAssociationResult, EditorCapabilities, EditorRegistrationStatus, EditorScope, EmbeddedAppAccessOptions, EmbeddedAppDescriptor, EmbeddedAppHandle, EmbeddingContext, type Event, HostCapabilities, HostTransport, type IDisposable, JsonFormatOptions, JsonValue, type MessageEndpoint, type MessageLikeEvent, OT_EDIT_TRANSFORM, OtPeer, OtType, PresentationMode, PresentationPreferences, ScopeRegistration, SyncedTextDocument, TextComponent, TextDocumentEditorOptions, TextDocumentSync, TextDocumentSyncOptions, TextEdit, TextOperation, TextOperationBuilder, TrackedOffset, VsCodeAppEmbeddingEventsProxy, VsCodeAppHostClient, VsCodeAppHostClientOptions, VsCodeAppHostProxy, WebEditorClient, WebEditorClientOptions, WebEditorClientState, WebEditorClientTransportProxy, WebEditorHost, WebEditorHostOptions, WebEditorHostProxy, WebEditorHostTransportProxy, WebEditorPresentationHostProxy, WebEditorPresentationProxy, WebEditorProxy, WebEditorUpdate, WindowMessageTransport, applyContentEdits, applyTextEdits, contentEditsOt, createWindowParentConnection, decodeFromEditor, diffContent, diffText, encodeForEditor, mapContentOffset, mapThrough, textOperationOt, transformContentEdits, vscodeAppEmbeddingEventsInterface, vscodeAppHostInterface, webEditorClientTransportInterface, webEditorHostInterface, webEditorHostTransportInterface, webEditorInterface, webEditorPresentationHostInterface, webEditorPresentationInterface };
2660
3136
  //# sourceMappingURL=index.d.ts.map