@lvce-editor/rpc-registry 9.41.0 → 9.43.0

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.
@@ -1,28 +1,71 @@
1
1
  import * as RpcRegistry from "../RpcRegistry/RpcRegistry.js";
2
2
  export const createLazyRpc = (rpcId) => {
3
- let rpcPromise;
3
+ let activeRpc;
4
4
  let factory;
5
- const createRpc = async () => {
5
+ let generation = 0;
6
+ let rpcPromise;
7
+ const resetListeners = new Set();
8
+ const createRpc = async (expectedGeneration) => {
6
9
  const rpc = await factory();
10
+ if (generation !== expectedGeneration) {
11
+ await rpc.dispose();
12
+ throw new Error('Lazy RPC launch was superseded');
13
+ }
14
+ activeRpc = rpc;
7
15
  RpcRegistry.set(rpcId, rpc);
16
+ return rpc;
8
17
  };
9
18
  const ensureRpc = async () => {
19
+ if (activeRpc) {
20
+ return activeRpc;
21
+ }
10
22
  if (!rpcPromise) {
11
- rpcPromise = createRpc();
23
+ const pending = createRpc(generation);
24
+ rpcPromise = pending;
25
+ void pending.catch(() => {
26
+ if (rpcPromise === pending) {
27
+ rpcPromise = undefined;
28
+ }
29
+ });
30
+ }
31
+ return rpcPromise;
32
+ };
33
+ const clear = async (reason, notify) => {
34
+ generation++;
35
+ const rpc = activeRpc;
36
+ activeRpc = undefined;
37
+ rpcPromise = undefined;
38
+ if (rpc && RpcRegistry.get(rpcId) === rpc) {
39
+ RpcRegistry.remove(rpcId);
40
+ }
41
+ if (notify) {
42
+ for (const listener of resetListeners) {
43
+ listener(reason);
44
+ }
12
45
  }
13
- await rpcPromise;
46
+ await rpc?.dispose();
14
47
  };
15
48
  return {
49
+ dispose() {
50
+ return clear(undefined, false);
51
+ },
16
52
  async invoke(method, ...params) {
17
- await ensureRpc();
18
- const rpc = RpcRegistry.get(rpcId);
53
+ const rpc = await ensureRpc();
19
54
  return rpc.invoke(method, ...params);
20
55
  },
21
56
  async invokeAndTransfer(method, ...params) {
22
- await ensureRpc();
23
- const rpc = RpcRegistry.get(rpcId);
57
+ const rpc = await ensureRpc();
24
58
  return rpc.invokeAndTransfer(method, ...params);
25
59
  },
60
+ onDidReset(listener) {
61
+ resetListeners.add(listener);
62
+ return () => {
63
+ resetListeners.delete(listener);
64
+ };
65
+ },
66
+ reset(reason) {
67
+ return clear(reason, true);
68
+ },
26
69
  setFactory(value) {
27
70
  factory = value;
28
71
  },
@@ -0,0 +1,6 @@
1
+ export declare const dispose: () => Promise<void>, invoke: (method: string, ...params: readonly any[]) => Promise<any>, invokeAndTransfer: (method: string, ...params: readonly any[]) => Promise<any>, onDidReset: (listener: (reason: unknown) => void) => () => void, reset: (reason?: unknown) => Promise<void>, setFactory: (value: () => Promise<import("@lvce-editor/rpc").Rpc>) => void;
2
+ export declare const createInstance: (instanceId: string, rendererUid: number, x: number, y: number, width: number, height: number, editorUid: number) => Promise<void>;
3
+ export declare const loadContentInstance: (instanceId: string) => Promise<void>;
4
+ export declare const diffInstance: (instanceId: string) => Promise<readonly number[]>;
5
+ export declare const renderInstance: (instanceId: string, diffResult: readonly number[]) => Promise<readonly (readonly any[])[]>;
6
+ export declare const disposeInstance: (instanceId: string) => Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { RpcId } from '@lvce-editor/constants';
2
+ import { createLazyRpc } from "../CreateLazyRpc/CreateLazyRpc.js";
3
+ const rpc = createLazyRpc(RpcId.FindWidgetWorker);
4
+ export const { dispose, invoke, invokeAndTransfer, onDidReset, reset, setFactory } = rpc;
5
+ export const createInstance = async (instanceId, rendererUid, x, y, width, height, editorUid) => {
6
+ await invoke('FindWidget.createInstance', instanceId, rendererUid, x, y, width, height, editorUid);
7
+ };
8
+ export const loadContentInstance = async (instanceId) => {
9
+ await invoke('FindWidget.loadContentInstance', instanceId);
10
+ };
11
+ export const diffInstance = async (instanceId) => {
12
+ return invoke('FindWidget.diffInstance', instanceId);
13
+ };
14
+ export const renderInstance = async (instanceId, diffResult) => {
15
+ return invoke('FindWidget.renderInstance', instanceId, diffResult);
16
+ };
17
+ export const disposeInstance = async (instanceId) => {
18
+ await invoke('FindWidget.disposeInstance', instanceId);
19
+ };
@@ -1,6 +1,9 @@
1
1
  import type { Rpc } from '@lvce-editor/rpc';
2
2
  export interface LazyRpc {
3
+ readonly dispose: () => Promise<void>;
3
4
  readonly invoke: (method: string, ...params: readonly any[]) => Promise<any>;
4
5
  readonly invokeAndTransfer: (method: string, ...params: readonly any[]) => Promise<any>;
6
+ readonly onDidReset: (listener: (reason: unknown) => void) => () => void;
7
+ readonly reset: (reason?: unknown) => Promise<void>;
5
8
  readonly setFactory: (value: () => Promise<Rpc>) => void;
6
9
  }
@@ -24,6 +24,7 @@ export * as FilePermissionProcess from '../FilePermissionProcess/FilePermissionP
24
24
  export * as FileSearchWorker from '../FileSearchWorker/FileSearchWorker.ts';
25
25
  export * as FileSystemProcess from '../FileSystemProcess/FileSystemProcess.ts';
26
26
  export * as FileSystemWorker from '../FileSystemWorker/FileSystemWorker.ts';
27
+ export * as FindWidgetWorker from '../FindWidgetWorker/FindWidgetWorker.ts';
27
28
  export * as IconThemeWorker from '../IconThemeWorker/IconThemeWorker.ts';
28
29
  export * as IframeWorker from '../IframeWorker/IframeWorker.ts';
29
30
  export * as IpcType from '../IpcType/IpcType.ts';
@@ -55,4 +56,5 @@ export type * from '../MockRpc/MockRpc.ts';
55
56
  export type * from '../SearchResult/SearchResult.ts';
56
57
  export type * from '../Change/Change.ts';
57
58
  export type * from '../TextEdit/TextEdit.ts';
59
+ export type * from '../WidgetLifecycleRequest/WidgetLifecycleRequest.ts';
58
60
  export type * from '../DisposableMockRpc/DisposableMockRpc.ts';
@@ -23,6 +23,7 @@ export * as FilePermissionProcess from "../FilePermissionProcess/FilePermissionP
23
23
  export * as FileSearchWorker from "../FileSearchWorker/FileSearchWorker.js";
24
24
  export * as FileSystemProcess from "../FileSystemProcess/FileSystemProcess.js";
25
25
  export * as FileSystemWorker from "../FileSystemWorker/FileSystemWorker.js";
26
+ export * as FindWidgetWorker from "../FindWidgetWorker/FindWidgetWorker.js";
26
27
  export * as IconThemeWorker from "../IconThemeWorker/IconThemeWorker.js";
27
28
  export * as IframeWorker from "../IframeWorker/IframeWorker.js";
28
29
  export * as IpcType from "../IpcType/IpcType.js";
@@ -1,4 +1,10 @@
1
+ import type { WidgetLifecycleAttachRequest, WidgetLifecycleRemoveRequest } from '../WidgetLifecycleRequest/WidgetLifecycleRequest.ts';
1
2
  export declare const dispose: () => Promise<void>, invoke: (method: string, ...params: readonly unknown[]) => Promise<any>, invokeAndTransfer: (method: string, ...params: readonly unknown[]) => Promise<any>, registerMockRpc: (commandMap: Record<string, any>) => import("../DisposableMockRpc/DisposableMockRpc.ts").DisposableMockRpc, set: (rpc: import("@lvce-editor/rpc").Rpc) => void;
3
+ export declare const allocateWidgetRendererId: () => Promise<number>;
4
+ export declare const attachWidget: (request: WidgetLifecycleAttachRequest) => Promise<boolean>;
5
+ export declare const removeWidget: (request: WidgetLifecycleRemoveRequest) => Promise<void>;
6
+ export declare const removeWidgets: (requests: readonly WidgetLifecycleRemoveRequest[]) => Promise<void>;
7
+ export declare const updateWidget: (request: WidgetLifecycleAttachRequest) => Promise<boolean>;
2
8
  export declare const searchFileHtml: (uri: string) => Promise<readonly string[]>;
3
9
  export declare const getFilePathElectron: (file: File) => Promise<string>;
4
10
  export declare const handleModifiedStatusChange: (uri: string, modified: boolean) => Promise<void>;
@@ -28,6 +34,7 @@ export declare const sendMessagePortToChatMessageParsingWorker: (port: MessagePo
28
34
  export declare const sendMessagePortToMainAreaWorker: (port: MessagePort, rpcId: number) => Promise<void>;
29
35
  export declare const sendMessagePortToTerminalProcess: (port: MessagePort, rpcId: number) => Promise<void>;
30
36
  export declare const sendMessagePortToTextSearchWorker: (port: MessagePort, rpcId: number) => Promise<void>;
37
+ export declare const sendMessagePortToDialogWorker: (port: MessagePort) => Promise<void>;
31
38
  export declare const sendMessagePortToAuthWorker: (port: MessagePort, rpcId: number) => Promise<void>;
32
39
  export declare const sendMessagePortToAuthProcess: (port: MessagePort, rpcId: number) => Promise<void>;
33
40
  export declare const sendMessagePortToFilePermissionProcess: (port: MessagePort, rpcId: number) => Promise<void>;
@@ -7,6 +7,21 @@ import * as ProcessExplorer from "../ProcessExplorer/ProcessExplorer.js";
7
7
  import * as RpcFactory from "../RpcFactory/RpcFactory.js";
8
8
  import * as TextMeasurementWorker from "../TextMeasurementWorker/TextMeasurementWorker.js";
9
9
  export const { dispose, invoke, invokeAndTransfer, registerMockRpc, set } = RpcFactory.create(RpcId.RendererWorker);
10
+ export const allocateWidgetRendererId = async () => {
11
+ return invoke('WidgetLifecycle.allocateRendererId');
12
+ };
13
+ export const attachWidget = async (request) => {
14
+ return invoke('WidgetLifecycle.attach', request);
15
+ };
16
+ export const removeWidget = async (request) => {
17
+ await invoke('WidgetLifecycle.remove', request);
18
+ };
19
+ export const removeWidgets = async (requests) => {
20
+ await invoke('WidgetLifecycle.removeMany', requests);
21
+ };
22
+ export const updateWidget = async (request) => {
23
+ return invoke('WidgetLifecycle.update', request);
24
+ };
10
25
  export const searchFileHtml = async (uri) => {
11
26
  return invoke('ExtensionHost.searchFileWithHtml', uri);
12
27
  };
@@ -103,6 +118,10 @@ export const sendMessagePortToTextSearchWorker = async (port, rpcId) => {
103
118
  const command = 'HandleMessagePort.handleMessagePort';
104
119
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTextSearchWorker', port, command, rpcId);
105
120
  };
121
+ export const sendMessagePortToDialogWorker = async (port) => {
122
+ const command = 'HandleMessagePort.handleMessagePort';
123
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
124
+ };
106
125
  export const sendMessagePortToAuthWorker = async (port, rpcId) => {
107
126
  const command = 'HandleMessagePort.handleMessagePort';
108
127
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToAuthWorker', port, command, rpcId);
@@ -1,6 +1,7 @@
1
1
  import type { BulkReplacementEdit } from '../BulkReplacementEdit/BulkReplacementEdit.ts';
2
2
  import type { ConfirmPromptOptions } from '../ConfirmPromptOptions/ConfirmPromptOptions.ts';
3
3
  import type { SearchResult } from '../SearchResult/SearchResult.ts';
4
+ import type { WidgetLifecycleAttachRequest, WidgetLifecycleRemoveRequest } from '../WidgetLifecycleRequest/WidgetLifecycleRequest.ts';
4
5
  export interface RendererWorkerApi {
5
6
  readonly 'About.focusNext': () => Promise<void>;
6
7
  readonly 'About.focusPrevious': () => Promise<void>;
@@ -272,6 +273,11 @@ export interface RendererWorkerApi {
272
273
  readonly 'WebView.registerInterceptor': (id: number, port: MessagePort) => Promise<void>;
273
274
  readonly 'WebView.setPort': (id: number, port: MessagePort, origin: string, portType: string) => Promise<void>;
274
275
  readonly 'WebView.unregisterInterceptor': (id: number) => Promise<void>;
276
+ readonly 'WidgetLifecycle.allocateRendererId': () => Promise<number>;
277
+ readonly 'WidgetLifecycle.attach': (request: WidgetLifecycleAttachRequest) => Promise<boolean>;
278
+ readonly 'WidgetLifecycle.remove': (request: WidgetLifecycleRemoveRequest) => Promise<void>;
279
+ readonly 'WidgetLifecycle.removeMany': (requests: readonly WidgetLifecycleRemoveRequest[]) => Promise<void>;
280
+ readonly 'WidgetLifecycle.update': (request: WidgetLifecycleAttachRequest) => Promise<boolean>;
275
281
  readonly 'Workspace.getPath': () => Promise<string>;
276
282
  readonly 'Workspace.setPath': (uri: string) => Promise<void>;
277
283
  }
@@ -0,0 +1,15 @@
1
+ export interface WidgetLifecycleAttachRequest {
2
+ readonly commands: readonly (readonly any[])[];
3
+ readonly editorUid: number;
4
+ readonly instanceId: string;
5
+ readonly intentSequence: number;
6
+ readonly kind: string;
7
+ readonly rendererUid: number;
8
+ }
9
+ export interface WidgetLifecycleRemoveRequest {
10
+ readonly editorUid: number;
11
+ readonly instanceId: string;
12
+ readonly intentSequence: number;
13
+ readonly kind: string;
14
+ readonly rendererUid: number;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/rpc-registry",
3
- "version": "9.41.0",
3
+ "version": "9.43.0",
4
4
  "description": "Rpc Registry",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,7 +13,7 @@
13
13
  "main": "dist/index.js",
14
14
  "dependencies": {
15
15
  "@lvce-editor/assert": "^1.5.1",
16
- "@lvce-editor/constants": "^5.22.0",
16
+ "@lvce-editor/constants": "^5.23.0",
17
17
  "@lvce-editor/rpc": "^6.4.0"
18
18
  },
19
19
  "exports": "./dist/index.js",