@lvce-editor/extension-host-worker 8.40.0 → 8.42.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.
- package/dist/extension-api/index.js +109 -3
- package/dist/extension-api/parts/ViewRegistry/ViewRegistry.js +110 -3
- package/dist/extensionHostWorkerMain.js +17 -4
- package/extension-api/dist/index.d.ts +1 -1
- package/extension-api/dist/parts/View/View.d.ts +7 -2
- package/extension-api/dist/parts/ViewRegistry/ViewRegistry.d.ts +1 -1
- package/extension-api/dist/parts/ViewRegistry/ViewRegistry.js +109 -3
- package/extension-api/package.json +1 -1
- package/extension-api/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -2404,9 +2404,11 @@ var diffTree = (oldNodes, newNodes) => {
|
|
|
2404
2404
|
// packages/extension-api/src/parts/ViewRegistry/ViewRegistry.ts
|
|
2405
2405
|
var views = /* @__PURE__ */ Object.create(null);
|
|
2406
2406
|
var instances = /* @__PURE__ */ Object.create(null);
|
|
2407
|
+
var instanceUidsByView = /* @__PURE__ */ Object.create(null);
|
|
2407
2408
|
var renderedDoms = /* @__PURE__ */ Object.create(null);
|
|
2408
2409
|
var contexts = /* @__PURE__ */ Object.create(null);
|
|
2409
2410
|
var contextViewIds = /* @__PURE__ */ Object.create(null);
|
|
2411
|
+
var viewCommandDisposables = /* @__PURE__ */ Object.create(null);
|
|
2410
2412
|
var assertBoolean = (value, message) => {
|
|
2411
2413
|
if (value !== void 0 && typeof value !== "boolean") {
|
|
2412
2414
|
throw new ExtensionApiError(message);
|
|
@@ -2449,6 +2451,23 @@ var assertEventListeners = (view) => {
|
|
|
2449
2451
|
assertEventListener(view.id, listener, index);
|
|
2450
2452
|
}
|
|
2451
2453
|
};
|
|
2454
|
+
var assertCommands = (view) => {
|
|
2455
|
+
if (view.commands === void 0) {
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
if (view.kind !== "virtualDom") {
|
|
2459
|
+
throw new ExtensionApiError(`view ${view.id} commands require virtualDom kind`);
|
|
2460
|
+
}
|
|
2461
|
+
if (!view.commands || typeof view.commands !== "object" || Array.isArray(view.commands)) {
|
|
2462
|
+
throw new ExtensionApiError(`view ${view.id} commands must be an object`);
|
|
2463
|
+
}
|
|
2464
|
+
for (const [id2, command] of Object.entries(view.commands)) {
|
|
2465
|
+
assertString(id2, `view ${view.id} command is missing id`);
|
|
2466
|
+
if (typeof command !== "function") {
|
|
2467
|
+
throw new ExtensionApiError(`view ${view.id} command ${id2} must be a function`);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
};
|
|
2452
2471
|
var assertView = (view) => {
|
|
2453
2472
|
if (!view) {
|
|
2454
2473
|
throw new ExtensionApiError("view is not defined");
|
|
@@ -2462,6 +2481,7 @@ var assertView = (view) => {
|
|
|
2462
2481
|
if (view.id in views) {
|
|
2463
2482
|
throw new ExtensionApiError(`view ${view.id} is already registered`);
|
|
2464
2483
|
}
|
|
2484
|
+
assertCommands(view);
|
|
2465
2485
|
assertEventListeners(view);
|
|
2466
2486
|
};
|
|
2467
2487
|
var toRegisteredView = (view) => {
|
|
@@ -2482,12 +2502,62 @@ var toRegisteredView = (view) => {
|
|
|
2482
2502
|
}
|
|
2483
2503
|
return registeredView;
|
|
2484
2504
|
};
|
|
2505
|
+
var getActiveViewInstance = (viewId) => {
|
|
2506
|
+
const instanceUids = instanceUidsByView[viewId];
|
|
2507
|
+
if (!instanceUids) {
|
|
2508
|
+
return void 0;
|
|
2509
|
+
}
|
|
2510
|
+
const uid = [...instanceUids].at(-1);
|
|
2511
|
+
if (uid === void 0) {
|
|
2512
|
+
return void 0;
|
|
2513
|
+
}
|
|
2514
|
+
return [uid, instances[uid]];
|
|
2515
|
+
};
|
|
2516
|
+
var executeViewCommand = async (view, commandId, args) => {
|
|
2517
|
+
const activeInstance = getActiveViewInstance(view.id);
|
|
2518
|
+
if (!activeInstance) {
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
const [uid, instance] = activeInstance;
|
|
2522
|
+
const command = view.commands[commandId];
|
|
2523
|
+
const newInstance = await command(instance, ...args);
|
|
2524
|
+
assertVirtualDomViewInstance(view.id, newInstance);
|
|
2525
|
+
instances[uid] = newInstance;
|
|
2526
|
+
await ExtensionManagementWorker_exports.invoke("Extensions.requestViewRerender", uid);
|
|
2527
|
+
};
|
|
2528
|
+
var registerViewCommands = (view) => {
|
|
2529
|
+
const disposables = [];
|
|
2530
|
+
try {
|
|
2531
|
+
for (const id2 of Object.keys(view.commands || {})) {
|
|
2532
|
+
disposables.push(
|
|
2533
|
+
registerCommand({
|
|
2534
|
+
execute(...args) {
|
|
2535
|
+
return executeViewCommand(view, id2, args);
|
|
2536
|
+
},
|
|
2537
|
+
id: id2
|
|
2538
|
+
})
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2541
|
+
} catch (error) {
|
|
2542
|
+
for (const disposable of disposables) {
|
|
2543
|
+
disposable.dispose();
|
|
2544
|
+
}
|
|
2545
|
+
throw error;
|
|
2546
|
+
}
|
|
2547
|
+
return disposables;
|
|
2548
|
+
};
|
|
2485
2549
|
var registerView = (view) => {
|
|
2486
2550
|
assertView(view);
|
|
2551
|
+
const commandDisposables = registerViewCommands(view);
|
|
2487
2552
|
views[view.id] = view;
|
|
2553
|
+
viewCommandDisposables[view.id] = commandDisposables;
|
|
2488
2554
|
return {
|
|
2489
2555
|
dispose() {
|
|
2556
|
+
for (const disposable of commandDisposables) {
|
|
2557
|
+
disposable.dispose();
|
|
2558
|
+
}
|
|
2490
2559
|
delete views[view.id];
|
|
2560
|
+
delete viewCommandDisposables[view.id];
|
|
2491
2561
|
}
|
|
2492
2562
|
};
|
|
2493
2563
|
};
|
|
@@ -2653,6 +2723,23 @@ var withFocusSelector = async (result, instance, contextChange) => {
|
|
|
2653
2723
|
focusSelector
|
|
2654
2724
|
};
|
|
2655
2725
|
};
|
|
2726
|
+
var withTitle = async (result, instance) => {
|
|
2727
|
+
if (typeof instance.renderTitle !== "function") {
|
|
2728
|
+
return result;
|
|
2729
|
+
}
|
|
2730
|
+
const title = await instance.renderTitle();
|
|
2731
|
+
if (typeof title !== "string") {
|
|
2732
|
+
throw new ExtensionApiError("view renderTitle result must be a string");
|
|
2733
|
+
}
|
|
2734
|
+
return {
|
|
2735
|
+
...result,
|
|
2736
|
+
title
|
|
2737
|
+
};
|
|
2738
|
+
};
|
|
2739
|
+
var withRenderMetadata = async (result, instance, contextChange) => {
|
|
2740
|
+
const resultWithFocus = await withFocusSelector(result, instance, contextChange);
|
|
2741
|
+
return withTitle(resultWithFocus, instance);
|
|
2742
|
+
};
|
|
2656
2743
|
var maybeClearContext = async (uid, viewId) => {
|
|
2657
2744
|
if (!contexts[uid]) {
|
|
2658
2745
|
return;
|
|
@@ -2684,6 +2771,9 @@ var createViewInstance = async (viewId, uid, context) => {
|
|
|
2684
2771
|
});
|
|
2685
2772
|
assertVirtualDomViewInstance(viewId, instance);
|
|
2686
2773
|
instances[uid] = instance;
|
|
2774
|
+
const instanceUids = instanceUidsByView[viewId] || /* @__PURE__ */ new Set();
|
|
2775
|
+
instanceUids.add(uid);
|
|
2776
|
+
instanceUidsByView[viewId] = instanceUids;
|
|
2687
2777
|
contextViewIds[uid] = viewId;
|
|
2688
2778
|
const dom = await renderDom(instance);
|
|
2689
2779
|
renderedDoms[uid] = dom;
|
|
@@ -2692,22 +2782,25 @@ var createViewInstance = async (viewId, uid, context) => {
|
|
|
2692
2782
|
type: "setDom"
|
|
2693
2783
|
};
|
|
2694
2784
|
const contextChange = await maybeNotifyContextChanged(uid, viewId, instance);
|
|
2695
|
-
return
|
|
2785
|
+
return withRenderMetadata(result, instance, contextChange);
|
|
2696
2786
|
};
|
|
2697
2787
|
var dispatchViewEvent = async (uid, event) => {
|
|
2698
2788
|
const instance = getVirtualDomInstance(uid);
|
|
2789
|
+
const instanceUids = instanceUidsByView[contextViewIds[uid]];
|
|
2790
|
+
instanceUids.delete(uid);
|
|
2791
|
+
instanceUids.add(uid);
|
|
2699
2792
|
if (typeof instance.handleEvent === "function") {
|
|
2700
2793
|
await instance.handleEvent(event);
|
|
2701
2794
|
}
|
|
2702
2795
|
const result = await renderPatches(uid, instance);
|
|
2703
2796
|
const contextChange = await maybeNotifyContextChanged(uid, contextViewIds[uid], instance);
|
|
2704
|
-
return
|
|
2797
|
+
return withRenderMetadata(result, instance, contextChange);
|
|
2705
2798
|
};
|
|
2706
2799
|
var renderViewInstance = async (uid) => {
|
|
2707
2800
|
const instance = getVirtualDomInstance(uid);
|
|
2708
2801
|
const result = await renderPatches(uid, instance);
|
|
2709
2802
|
const contextChange = await maybeNotifyContextChanged(uid, contextViewIds[uid], instance);
|
|
2710
|
-
return
|
|
2803
|
+
return withRenderMetadata(result, instance, contextChange);
|
|
2711
2804
|
};
|
|
2712
2805
|
var disposeViewInstance = async (uid) => {
|
|
2713
2806
|
const instance = instances[uid];
|
|
@@ -2715,6 +2808,12 @@ var disposeViewInstance = async (uid) => {
|
|
|
2715
2808
|
await instance.dispose();
|
|
2716
2809
|
}
|
|
2717
2810
|
await maybeClearContext(uid, contextViewIds[uid]);
|
|
2811
|
+
const viewId = contextViewIds[uid];
|
|
2812
|
+
const instanceUids = instanceUidsByView[viewId];
|
|
2813
|
+
instanceUids?.delete(uid);
|
|
2814
|
+
if (instanceUids?.size === 0) {
|
|
2815
|
+
delete instanceUidsByView[viewId];
|
|
2816
|
+
}
|
|
2718
2817
|
delete instances[uid];
|
|
2719
2818
|
delete renderedDoms[uid];
|
|
2720
2819
|
delete contextViewIds[uid];
|
|
@@ -2748,7 +2847,11 @@ var getViewRegistrySnapshot = () => {
|
|
|
2748
2847
|
};
|
|
2749
2848
|
var resetViewRegistry = () => {
|
|
2750
2849
|
for (const id2 of Object.keys(views)) {
|
|
2850
|
+
for (const disposable of viewCommandDisposables[id2] || []) {
|
|
2851
|
+
disposable.dispose();
|
|
2852
|
+
}
|
|
2751
2853
|
delete views[id2];
|
|
2854
|
+
delete viewCommandDisposables[id2];
|
|
2752
2855
|
}
|
|
2753
2856
|
for (const uid of Object.keys(instances)) {
|
|
2754
2857
|
delete instances[Number(uid)];
|
|
@@ -2762,6 +2865,9 @@ var resetViewRegistry = () => {
|
|
|
2762
2865
|
for (const uid of Object.keys(contextViewIds)) {
|
|
2763
2866
|
delete contextViewIds[Number(uid)];
|
|
2764
2867
|
}
|
|
2868
|
+
for (const viewId of Object.keys(instanceUidsByView)) {
|
|
2869
|
+
delete instanceUidsByView[viewId];
|
|
2870
|
+
}
|
|
2765
2871
|
};
|
|
2766
2872
|
|
|
2767
2873
|
// packages/extension-api/src/parts/ExtensionApiCommandMap/ExtensionApiCommandMap.ts
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ExtensionManagementWorker } from "@lvce-editor/rpc-registry";
|
|
2
2
|
import { diffTree } from "@lvce-editor/virtual-dom-worker";
|
|
3
|
+
import { registerCommand } from "../CommandRegistry/CommandRegistry.js";
|
|
3
4
|
import { ExtensionApiError } from "../ExtensionApiError/ExtensionApiError.js";
|
|
4
5
|
const views = /* @__PURE__ */ Object.create(null);
|
|
5
6
|
const instances = /* @__PURE__ */ Object.create(null);
|
|
7
|
+
const instanceUidsByView = /* @__PURE__ */ Object.create(null);
|
|
6
8
|
const renderedDoms = /* @__PURE__ */ Object.create(null);
|
|
7
9
|
const contexts = /* @__PURE__ */ Object.create(null);
|
|
8
10
|
const contextViewIds = /* @__PURE__ */ Object.create(null);
|
|
11
|
+
const viewCommandDisposables = /* @__PURE__ */ Object.create(null);
|
|
9
12
|
const assertBoolean = (value, message) => {
|
|
10
13
|
if (value !== void 0 && typeof value !== "boolean") {
|
|
11
14
|
throw new ExtensionApiError(message);
|
|
@@ -48,6 +51,23 @@ const assertEventListeners = (view) => {
|
|
|
48
51
|
assertEventListener(view.id, listener, index);
|
|
49
52
|
}
|
|
50
53
|
};
|
|
54
|
+
const assertCommands = (view) => {
|
|
55
|
+
if (view.commands === void 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (view.kind !== "virtualDom") {
|
|
59
|
+
throw new ExtensionApiError(`view ${view.id} commands require virtualDom kind`);
|
|
60
|
+
}
|
|
61
|
+
if (!view.commands || typeof view.commands !== "object" || Array.isArray(view.commands)) {
|
|
62
|
+
throw new ExtensionApiError(`view ${view.id} commands must be an object`);
|
|
63
|
+
}
|
|
64
|
+
for (const [id, command] of Object.entries(view.commands)) {
|
|
65
|
+
assertString(id, `view ${view.id} command is missing id`);
|
|
66
|
+
if (typeof command !== "function") {
|
|
67
|
+
throw new ExtensionApiError(`view ${view.id} command ${id} must be a function`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
51
71
|
const assertView = (view) => {
|
|
52
72
|
if (!view) {
|
|
53
73
|
throw new ExtensionApiError("view is not defined");
|
|
@@ -61,6 +81,7 @@ const assertView = (view) => {
|
|
|
61
81
|
if (view.id in views) {
|
|
62
82
|
throw new ExtensionApiError(`view ${view.id} is already registered`);
|
|
63
83
|
}
|
|
84
|
+
assertCommands(view);
|
|
64
85
|
assertEventListeners(view);
|
|
65
86
|
};
|
|
66
87
|
const toRegisteredView = (view) => {
|
|
@@ -81,12 +102,62 @@ const toRegisteredView = (view) => {
|
|
|
81
102
|
}
|
|
82
103
|
return registeredView;
|
|
83
104
|
};
|
|
105
|
+
const getActiveViewInstance = (viewId) => {
|
|
106
|
+
const instanceUids = instanceUidsByView[viewId];
|
|
107
|
+
if (!instanceUids) {
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
const uid = [...instanceUids].at(-1);
|
|
111
|
+
if (uid === void 0) {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
return [uid, instances[uid]];
|
|
115
|
+
};
|
|
116
|
+
const executeViewCommand = async (view, commandId, args) => {
|
|
117
|
+
const activeInstance = getActiveViewInstance(view.id);
|
|
118
|
+
if (!activeInstance) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const [uid, instance] = activeInstance;
|
|
122
|
+
const command = view.commands[commandId];
|
|
123
|
+
const newInstance = await command(instance, ...args);
|
|
124
|
+
assertVirtualDomViewInstance(view.id, newInstance);
|
|
125
|
+
instances[uid] = newInstance;
|
|
126
|
+
await ExtensionManagementWorker.invoke("Extensions.requestViewRerender", uid);
|
|
127
|
+
};
|
|
128
|
+
const registerViewCommands = (view) => {
|
|
129
|
+
const disposables = [];
|
|
130
|
+
try {
|
|
131
|
+
for (const id of Object.keys(view.commands || {})) {
|
|
132
|
+
disposables.push(
|
|
133
|
+
registerCommand({
|
|
134
|
+
execute(...args) {
|
|
135
|
+
return executeViewCommand(view, id, args);
|
|
136
|
+
},
|
|
137
|
+
id
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
for (const disposable of disposables) {
|
|
143
|
+
disposable.dispose();
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
return disposables;
|
|
148
|
+
};
|
|
84
149
|
const registerView = (view) => {
|
|
85
150
|
assertView(view);
|
|
151
|
+
const commandDisposables = registerViewCommands(view);
|
|
86
152
|
views[view.id] = view;
|
|
153
|
+
viewCommandDisposables[view.id] = commandDisposables;
|
|
87
154
|
return {
|
|
88
155
|
dispose() {
|
|
156
|
+
for (const disposable of commandDisposables) {
|
|
157
|
+
disposable.dispose();
|
|
158
|
+
}
|
|
89
159
|
delete views[view.id];
|
|
160
|
+
delete viewCommandDisposables[view.id];
|
|
90
161
|
}
|
|
91
162
|
};
|
|
92
163
|
};
|
|
@@ -252,6 +323,23 @@ const withFocusSelector = async (result, instance, contextChange) => {
|
|
|
252
323
|
focusSelector
|
|
253
324
|
};
|
|
254
325
|
};
|
|
326
|
+
const withTitle = async (result, instance) => {
|
|
327
|
+
if (typeof instance.renderTitle !== "function") {
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
330
|
+
const title = await instance.renderTitle();
|
|
331
|
+
if (typeof title !== "string") {
|
|
332
|
+
throw new ExtensionApiError("view renderTitle result must be a string");
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
...result,
|
|
336
|
+
title
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
const withRenderMetadata = async (result, instance, contextChange) => {
|
|
340
|
+
const resultWithFocus = await withFocusSelector(result, instance, contextChange);
|
|
341
|
+
return withTitle(resultWithFocus, instance);
|
|
342
|
+
};
|
|
255
343
|
const maybeClearContext = async (uid, viewId) => {
|
|
256
344
|
if (!contexts[uid]) {
|
|
257
345
|
return;
|
|
@@ -283,6 +371,9 @@ const createViewInstance = async (viewId, uid, context) => {
|
|
|
283
371
|
});
|
|
284
372
|
assertVirtualDomViewInstance(viewId, instance);
|
|
285
373
|
instances[uid] = instance;
|
|
374
|
+
const instanceUids = instanceUidsByView[viewId] || /* @__PURE__ */ new Set();
|
|
375
|
+
instanceUids.add(uid);
|
|
376
|
+
instanceUidsByView[viewId] = instanceUids;
|
|
286
377
|
contextViewIds[uid] = viewId;
|
|
287
378
|
const dom = await renderDom(instance);
|
|
288
379
|
renderedDoms[uid] = dom;
|
|
@@ -291,22 +382,25 @@ const createViewInstance = async (viewId, uid, context) => {
|
|
|
291
382
|
type: "setDom"
|
|
292
383
|
};
|
|
293
384
|
const contextChange = await maybeNotifyContextChanged(uid, viewId, instance);
|
|
294
|
-
return
|
|
385
|
+
return withRenderMetadata(result, instance, contextChange);
|
|
295
386
|
};
|
|
296
387
|
const dispatchViewEvent = async (uid, event) => {
|
|
297
388
|
const instance = getVirtualDomInstance(uid);
|
|
389
|
+
const instanceUids = instanceUidsByView[contextViewIds[uid]];
|
|
390
|
+
instanceUids.delete(uid);
|
|
391
|
+
instanceUids.add(uid);
|
|
298
392
|
if (typeof instance.handleEvent === "function") {
|
|
299
393
|
await instance.handleEvent(event);
|
|
300
394
|
}
|
|
301
395
|
const result = await renderPatches(uid, instance);
|
|
302
396
|
const contextChange = await maybeNotifyContextChanged(uid, contextViewIds[uid], instance);
|
|
303
|
-
return
|
|
397
|
+
return withRenderMetadata(result, instance, contextChange);
|
|
304
398
|
};
|
|
305
399
|
const renderViewInstance = async (uid) => {
|
|
306
400
|
const instance = getVirtualDomInstance(uid);
|
|
307
401
|
const result = await renderPatches(uid, instance);
|
|
308
402
|
const contextChange = await maybeNotifyContextChanged(uid, contextViewIds[uid], instance);
|
|
309
|
-
return
|
|
403
|
+
return withRenderMetadata(result, instance, contextChange);
|
|
310
404
|
};
|
|
311
405
|
const disposeViewInstance = async (uid) => {
|
|
312
406
|
const instance = instances[uid];
|
|
@@ -314,6 +408,12 @@ const disposeViewInstance = async (uid) => {
|
|
|
314
408
|
await instance.dispose();
|
|
315
409
|
}
|
|
316
410
|
await maybeClearContext(uid, contextViewIds[uid]);
|
|
411
|
+
const viewId = contextViewIds[uid];
|
|
412
|
+
const instanceUids = instanceUidsByView[viewId];
|
|
413
|
+
instanceUids?.delete(uid);
|
|
414
|
+
if (instanceUids?.size === 0) {
|
|
415
|
+
delete instanceUidsByView[viewId];
|
|
416
|
+
}
|
|
317
417
|
delete instances[uid];
|
|
318
418
|
delete renderedDoms[uid];
|
|
319
419
|
delete contextViewIds[uid];
|
|
@@ -347,7 +447,11 @@ const getViewRegistrySnapshot = () => {
|
|
|
347
447
|
};
|
|
348
448
|
const resetViewRegistry = () => {
|
|
349
449
|
for (const id of Object.keys(views)) {
|
|
450
|
+
for (const disposable of viewCommandDisposables[id] || []) {
|
|
451
|
+
disposable.dispose();
|
|
452
|
+
}
|
|
350
453
|
delete views[id];
|
|
454
|
+
delete viewCommandDisposables[id];
|
|
351
455
|
}
|
|
352
456
|
for (const uid of Object.keys(instances)) {
|
|
353
457
|
delete instances[Number(uid)];
|
|
@@ -361,6 +465,9 @@ const resetViewRegistry = () => {
|
|
|
361
465
|
for (const uid of Object.keys(contextViewIds)) {
|
|
362
466
|
delete contextViewIds[Number(uid)];
|
|
363
467
|
}
|
|
468
|
+
for (const viewId of Object.keys(instanceUidsByView)) {
|
|
469
|
+
delete instanceUidsByView[viewId];
|
|
470
|
+
}
|
|
364
471
|
};
|
|
365
472
|
export {
|
|
366
473
|
createViewInstance,
|
|
@@ -3855,6 +3855,19 @@ const renderDom = async instance => {
|
|
|
3855
3855
|
}
|
|
3856
3856
|
return dom;
|
|
3857
3857
|
};
|
|
3858
|
+
const withTitle = async (result, instance) => {
|
|
3859
|
+
if (typeof instance.renderTitle !== 'function') {
|
|
3860
|
+
return result;
|
|
3861
|
+
}
|
|
3862
|
+
const title = await instance.renderTitle();
|
|
3863
|
+
if (typeof title !== 'string') {
|
|
3864
|
+
throw new TypeError('view renderTitle result must be a string');
|
|
3865
|
+
}
|
|
3866
|
+
return {
|
|
3867
|
+
...result,
|
|
3868
|
+
title
|
|
3869
|
+
};
|
|
3870
|
+
};
|
|
3858
3871
|
const createViewInstance = async (viewId, uid, context) => {
|
|
3859
3872
|
const view = state$6.views[viewId];
|
|
3860
3873
|
if (!view) {
|
|
@@ -3872,10 +3885,10 @@ const createViewInstance = async (viewId, uid, context) => {
|
|
|
3872
3885
|
state$6.instances[uid] = instance;
|
|
3873
3886
|
const dom = await renderDom(instance);
|
|
3874
3887
|
state$6.renderedDoms[uid] = dom;
|
|
3875
|
-
return {
|
|
3888
|
+
return withTitle({
|
|
3876
3889
|
dom,
|
|
3877
3890
|
type: 'setDom'
|
|
3878
|
-
};
|
|
3891
|
+
}, instance);
|
|
3879
3892
|
};
|
|
3880
3893
|
const dispatchViewEvent = async (uid, event) => {
|
|
3881
3894
|
const instance = getVirtualDomInstance(uid);
|
|
@@ -3886,10 +3899,10 @@ const dispatchViewEvent = async (uid, event) => {
|
|
|
3886
3899
|
const newDom = await renderDom(instance);
|
|
3887
3900
|
state$6.renderedDoms[uid] = newDom;
|
|
3888
3901
|
const patches = diffTree(oldDom, newDom);
|
|
3889
|
-
return {
|
|
3902
|
+
return withTitle({
|
|
3890
3903
|
patches,
|
|
3891
3904
|
type: 'setPatches'
|
|
3892
|
-
};
|
|
3905
|
+
}, instance);
|
|
3893
3906
|
};
|
|
3894
3907
|
const saveViewInstanceState = async uid => {
|
|
3895
3908
|
const instance = getVirtualDomInstance(uid);
|
|
@@ -12,7 +12,7 @@ export { executeSourceControlAcceptInput, executeSourceControlAdd, executeSource
|
|
|
12
12
|
export { createViewInstance, dispatchViewEvent, disposeViewInstance, executeViewProvider, getViewRegistrySnapshot, renderViewInstance, registerView, resetViewRegistry, saveViewInstanceState, } from './parts/ViewRegistry/ViewRegistry.ts';
|
|
13
13
|
export { createOutputChannel, getOutputChannelRegistrySnapshot, resetOutputChannelRegistry } from './parts/OutputChannel/OutputChannel.ts';
|
|
14
14
|
export { getStatusBarItemProviderRegistrySnapshot, registerStatusBarItemProvider, resetStatusBarItemProviderRegistry, } from './parts/StatusBar/StatusBar.ts';
|
|
15
|
-
export type { RegisteredView, View, ViewAction, ViewContext, ViewEvent, ViewKind, MenuEntry, ViewRegistrySnapshot, ViewRenderResult, VirtualDomViewInstance, } from './parts/View/View.ts';
|
|
15
|
+
export type { RegisteredView, View, ViewAction, ViewCommand, ViewContext, ViewEvent, ViewKind, MenuEntry, ViewRegistrySnapshot, ViewRenderResult, VirtualDomViewInstance, } from './parts/View/View.ts';
|
|
16
16
|
export { handleExtensionManagementMessagePort } from './parts/HandleExtensionManagementMessagePort/HandleExtensionManagementMessagePort.ts';
|
|
17
17
|
export type { Command } from './parts/Command/Command.ts';
|
|
18
18
|
export type { CommandCallback } from './parts/CommandCallback/CommandCallback.ts';
|
|
@@ -42,10 +42,13 @@ export interface VirtualDomViewInstance {
|
|
|
42
42
|
readonly render: () => readonly VirtualDomNode[] | Promise<readonly VirtualDomNode[]>;
|
|
43
43
|
readonly renderActions?: () => readonly ViewAction[] | Promise<readonly ViewAction[]>;
|
|
44
44
|
readonly renderFocus?: (oldContext: Readonly<Record<string, boolean>>, newContext: Readonly<Record<string, boolean>>) => string | Promise<string>;
|
|
45
|
+
readonly renderTitle?: () => string | Promise<string>;
|
|
45
46
|
readonly saveState?: () => unknown;
|
|
46
47
|
}
|
|
47
|
-
export
|
|
48
|
-
|
|
48
|
+
export type ViewCommand<State = VirtualDomViewInstance, Args extends readonly any[] = readonly any[]> = (state: State, ...args: Args) => State | Promise<State>;
|
|
49
|
+
export interface View<State = unknown> {
|
|
50
|
+
readonly commands?: Readonly<Record<string, ViewCommand<State>>>;
|
|
51
|
+
readonly create: (context?: ViewContext) => State | Promise<State>;
|
|
49
52
|
readonly displayName?: string;
|
|
50
53
|
readonly eventListeners?: readonly DomEventListener[];
|
|
51
54
|
readonly icon?: string;
|
|
@@ -69,11 +72,13 @@ export interface ViewRegistrySnapshot {
|
|
|
69
72
|
export interface ViewRenderResultDom {
|
|
70
73
|
readonly dom: readonly VirtualDomNode[];
|
|
71
74
|
readonly focusSelector?: string;
|
|
75
|
+
readonly title?: string;
|
|
72
76
|
readonly type: 'setDom';
|
|
73
77
|
}
|
|
74
78
|
export interface ViewRenderResultPatches {
|
|
75
79
|
readonly focusSelector?: string;
|
|
76
80
|
readonly patches: readonly unknown[];
|
|
81
|
+
readonly title?: string;
|
|
77
82
|
readonly type: 'setPatches';
|
|
78
83
|
}
|
|
79
84
|
export type ViewRenderResult = ViewRenderResultDom | ViewRenderResultPatches;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Disposable } from '../Disposable/Disposable.ts';
|
|
2
2
|
import type { MenuEntry, View, ViewAction, ViewContext, ViewEvent, ViewRegistrySnapshot, ViewRenderResult } from '../View/View.ts';
|
|
3
|
-
export declare const registerView: (view: View) => Disposable;
|
|
3
|
+
export declare const registerView: <State>(view: View<State>) => Disposable;
|
|
4
4
|
export declare const executeViewProvider: (id: string) => unknown;
|
|
5
5
|
export declare const createViewInstance: (viewId: string, uid: number, context?: ViewContext) => Promise<ViewRenderResult>;
|
|
6
6
|
export declare const dispatchViewEvent: (uid: number, event: ViewEvent) => Promise<ViewRenderResult>;
|