@lvce-editor/main-area-worker 8.13.0 → 8.14.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/mainAreaWorkerMain.js +81 -20
- package/package.json +1 -1
|
@@ -88,7 +88,13 @@ const terminate = () => {
|
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
const getGroupIndexById = (state, groupId) => {
|
|
91
|
-
|
|
91
|
+
const {
|
|
92
|
+
layout
|
|
93
|
+
} = state;
|
|
94
|
+
const {
|
|
95
|
+
groups
|
|
96
|
+
} = layout;
|
|
97
|
+
return groups.findIndex(group => group.id === groupId);
|
|
92
98
|
};
|
|
93
99
|
|
|
94
100
|
const redistributeSizesWithRounding = groups => {
|
|
@@ -181,7 +187,13 @@ const closeTab = (state, groupId, tabId) => {
|
|
|
181
187
|
};
|
|
182
188
|
|
|
183
189
|
const getFocusedGroup = state => {
|
|
184
|
-
|
|
190
|
+
const {
|
|
191
|
+
layout
|
|
192
|
+
} = state;
|
|
193
|
+
const {
|
|
194
|
+
groups
|
|
195
|
+
} = layout;
|
|
196
|
+
return groups.find(group => group.focused);
|
|
185
197
|
};
|
|
186
198
|
|
|
187
199
|
const closeActiveEditor = state => {
|
|
@@ -1669,6 +1681,7 @@ const copyPath$1 = async (state, path) => {
|
|
|
1669
1681
|
|
|
1670
1682
|
const copyRelativePath$1 = async (state, path) => {
|
|
1671
1683
|
string(path);
|
|
1684
|
+
// TODO use clipboard worker
|
|
1672
1685
|
const relativePath = await invoke('Workspace.pathBaseName', path);
|
|
1673
1686
|
await invoke('ClipBoard.writeText', relativePath);
|
|
1674
1687
|
return state;
|
|
@@ -2344,6 +2357,11 @@ const handleClickTogglePreview = async state => {
|
|
|
2344
2357
|
return state;
|
|
2345
2358
|
};
|
|
2346
2359
|
|
|
2360
|
+
const CloseGroup = 'close-group';
|
|
2361
|
+
const RetryOpen = 'retry-open';
|
|
2362
|
+
const SplitRight = 'split-right';
|
|
2363
|
+
const TogglePreview$1 = 'toggle-preview';
|
|
2364
|
+
|
|
2347
2365
|
const getBasename$1 = uri => {
|
|
2348
2366
|
const lastSlashIndex = uri.lastIndexOf('/');
|
|
2349
2367
|
if (lastSlashIndex === -1) {
|
|
@@ -2382,6 +2400,7 @@ const createEmptyGroup = (state, uri, requestId) => {
|
|
|
2382
2400
|
icon: '',
|
|
2383
2401
|
id: tabId,
|
|
2384
2402
|
isDirty: false,
|
|
2403
|
+
isPreview: false,
|
|
2385
2404
|
language: '',
|
|
2386
2405
|
loadingState: 'loading',
|
|
2387
2406
|
title,
|
|
@@ -2406,8 +2425,12 @@ const createEmptyGroup = (state, uri, requestId) => {
|
|
|
2406
2425
|
};
|
|
2407
2426
|
|
|
2408
2427
|
const openTab = (state, groupId, tab) => {
|
|
2409
|
-
const
|
|
2428
|
+
const normalizedTab = {
|
|
2410
2429
|
...tab,
|
|
2430
|
+
isPreview: tab.isPreview ?? false
|
|
2431
|
+
};
|
|
2432
|
+
const newTab = 'id' in normalizedTab && normalizedTab.id !== undefined ? normalizedTab : {
|
|
2433
|
+
...normalizedTab,
|
|
2411
2434
|
id: create$1()
|
|
2412
2435
|
};
|
|
2413
2436
|
const {
|
|
@@ -2465,6 +2488,7 @@ const ensureActiveGroup = (state, uri) => {
|
|
|
2465
2488
|
icon: '',
|
|
2466
2489
|
id: tabId,
|
|
2467
2490
|
isDirty: false,
|
|
2491
|
+
isPreview: false,
|
|
2468
2492
|
language: '',
|
|
2469
2493
|
loadingState: 'loading',
|
|
2470
2494
|
title,
|
|
@@ -2936,17 +2960,17 @@ const handleClickAction = async (state, action, rawGroupId) => {
|
|
|
2936
2960
|
return state;
|
|
2937
2961
|
}
|
|
2938
2962
|
switch (action) {
|
|
2939
|
-
case
|
|
2963
|
+
case CloseGroup:
|
|
2940
2964
|
if (rawGroupId) {
|
|
2941
2965
|
const groupId = Number.parseInt(rawGroupId, 10);
|
|
2942
2966
|
return closeEditorGroup$1(state, groupId);
|
|
2943
2967
|
}
|
|
2944
2968
|
return state;
|
|
2945
|
-
case
|
|
2969
|
+
case RetryOpen:
|
|
2946
2970
|
return retryOpen(state);
|
|
2947
|
-
case
|
|
2971
|
+
case SplitRight:
|
|
2948
2972
|
return splitEditorGroup$1(state, activeGroup.id, Right);
|
|
2949
|
-
case
|
|
2973
|
+
case TogglePreview$1:
|
|
2950
2974
|
return handleClickTogglePreview(state);
|
|
2951
2975
|
default:
|
|
2952
2976
|
return state;
|
|
@@ -3085,6 +3109,7 @@ const newFile = async state => {
|
|
|
3085
3109
|
icon: '',
|
|
3086
3110
|
id: tabId,
|
|
3087
3111
|
isDirty: false,
|
|
3112
|
+
isPreview: false,
|
|
3088
3113
|
language: 'plaintext',
|
|
3089
3114
|
loadingState: 'loading',
|
|
3090
3115
|
title: 'Untitled',
|
|
@@ -3442,10 +3467,13 @@ const handleUriChange = async (state, oldUri, newUri) => {
|
|
|
3442
3467
|
};
|
|
3443
3468
|
|
|
3444
3469
|
const handleWorkspaceChange = state => {
|
|
3470
|
+
const {
|
|
3471
|
+
layout
|
|
3472
|
+
} = state;
|
|
3445
3473
|
return {
|
|
3446
3474
|
...state,
|
|
3447
3475
|
layout: {
|
|
3448
|
-
...
|
|
3476
|
+
...layout,
|
|
3449
3477
|
activeGroupId: undefined,
|
|
3450
3478
|
groups: []
|
|
3451
3479
|
}
|
|
@@ -3475,7 +3503,7 @@ const initialize = async () => {
|
|
|
3475
3503
|
};
|
|
3476
3504
|
|
|
3477
3505
|
const isValidTab = tab => {
|
|
3478
|
-
return tab && typeof tab.id === 'number' && typeof tab.title === 'string' && typeof tab.isDirty === 'boolean' && typeof tab.editorUid === 'number' && typeof tab.icon === 'string' && (tab.editorType === 'text' || tab.editorType === 'custom');
|
|
3506
|
+
return tab && typeof tab.id === 'number' && typeof tab.title === 'string' && typeof tab.isDirty === 'boolean' && typeof tab.isPreview === 'boolean' && typeof tab.editorUid === 'number' && typeof tab.icon === 'string' && (tab.editorType === 'text' || tab.editorType === 'custom');
|
|
3479
3507
|
};
|
|
3480
3508
|
|
|
3481
3509
|
const isValidEditorGroup = group => {
|
|
@@ -3512,23 +3540,31 @@ const tryRestoreLayout = savedState => {
|
|
|
3512
3540
|
const {
|
|
3513
3541
|
layout
|
|
3514
3542
|
} = savedState;
|
|
3515
|
-
if (!
|
|
3543
|
+
if (!layout || typeof layout !== 'object') {
|
|
3544
|
+
return undefined;
|
|
3545
|
+
}
|
|
3546
|
+
const rawLayout = layout;
|
|
3547
|
+
if (!Array.isArray(rawLayout.groups)) {
|
|
3516
3548
|
return undefined;
|
|
3517
3549
|
}
|
|
3518
3550
|
|
|
3519
3551
|
// Normalize all tabs to have editorUid: -1 so SelectTab will create viewlets
|
|
3520
3552
|
// Mark all restored tabs as not dirty
|
|
3521
3553
|
const normalizedLayout = {
|
|
3522
|
-
...
|
|
3523
|
-
groups:
|
|
3554
|
+
...rawLayout,
|
|
3555
|
+
groups: rawLayout.groups.map(group => ({
|
|
3524
3556
|
...group,
|
|
3525
|
-
tabs: group.tabs.map(tab => ({
|
|
3557
|
+
tabs: Array.isArray(group?.tabs) ? group.tabs.map(tab => ({
|
|
3526
3558
|
...tab,
|
|
3527
3559
|
editorUid: -1,
|
|
3528
|
-
isDirty: false
|
|
3529
|
-
|
|
3560
|
+
isDirty: false,
|
|
3561
|
+
isPreview: typeof tab?.isPreview === 'boolean' ? tab.isPreview : false
|
|
3562
|
+
})) : []
|
|
3530
3563
|
}))
|
|
3531
3564
|
};
|
|
3565
|
+
if (!isValidMainAreaLayout(normalizedLayout)) {
|
|
3566
|
+
return undefined;
|
|
3567
|
+
}
|
|
3532
3568
|
return normalizedLayout;
|
|
3533
3569
|
};
|
|
3534
3570
|
|
|
@@ -3817,6 +3853,28 @@ const getMenuEntries = async (state, props) => {
|
|
|
3817
3853
|
}
|
|
3818
3854
|
};
|
|
3819
3855
|
|
|
3856
|
+
const openUris = async (state, uris) => {
|
|
3857
|
+
if (uris.length === 0) {
|
|
3858
|
+
return state;
|
|
3859
|
+
}
|
|
3860
|
+
if (uris.length === 1) {
|
|
3861
|
+
return openUri(state, uris[0]);
|
|
3862
|
+
}
|
|
3863
|
+
let currentState = await openUri(state, uris[0]);
|
|
3864
|
+
const firstTab = findTabByUri(currentState, uris[0]);
|
|
3865
|
+
for (const uri of uris.slice(1)) {
|
|
3866
|
+
const existingTab = findTabByUri(currentState, uri);
|
|
3867
|
+
if (existingTab) {
|
|
3868
|
+
continue;
|
|
3869
|
+
}
|
|
3870
|
+
currentState = ensureActiveGroup(currentState, uri);
|
|
3871
|
+
}
|
|
3872
|
+
if (!firstTab) {
|
|
3873
|
+
return currentState;
|
|
3874
|
+
}
|
|
3875
|
+
return switchTab(currentState, firstTab.groupId, firstTab.tab.id);
|
|
3876
|
+
};
|
|
3877
|
+
|
|
3820
3878
|
const refresh = state => {
|
|
3821
3879
|
return {
|
|
3822
3880
|
...state
|
|
@@ -4169,7 +4227,8 @@ const renderError = errorMessage => {
|
|
|
4169
4227
|
}, text(`Error: ${errorMessage}`), {
|
|
4170
4228
|
childCount: 1,
|
|
4171
4229
|
className: `${Button} ${ButtonSecondary}`,
|
|
4172
|
-
'data-action':
|
|
4230
|
+
'data-action': RetryOpen,
|
|
4231
|
+
name: RetryOpen,
|
|
4173
4232
|
onClick: HandleClickAction,
|
|
4174
4233
|
type: Button$2
|
|
4175
4234
|
}, text('Retry')];
|
|
@@ -4313,9 +4372,9 @@ const renderEditorGroupActions = (group, groupIndex, splitButtonEnabled) => {
|
|
|
4313
4372
|
ariaLabel: 'Preview',
|
|
4314
4373
|
childCount: 1,
|
|
4315
4374
|
className: IconButton,
|
|
4316
|
-
'data-action':
|
|
4375
|
+
'data-action': TogglePreview$1,
|
|
4317
4376
|
'data-groupId': String(group.id),
|
|
4318
|
-
name:
|
|
4377
|
+
name: TogglePreview$1,
|
|
4319
4378
|
onClick: HandleClickAction,
|
|
4320
4379
|
title: togglePreview(),
|
|
4321
4380
|
type: Button$2
|
|
@@ -4329,8 +4388,9 @@ const renderEditorGroupActions = (group, groupIndex, splitButtonEnabled) => {
|
|
|
4329
4388
|
buttons.push({
|
|
4330
4389
|
childCount: 1,
|
|
4331
4390
|
className: EditorGroupActionButton + ' ' + SplitEditorGroupButton,
|
|
4332
|
-
'data-action':
|
|
4391
|
+
'data-action': SplitRight,
|
|
4333
4392
|
'data-groupId': String(group.id),
|
|
4393
|
+
name: SplitRight,
|
|
4334
4394
|
onClick: HandleClickAction,
|
|
4335
4395
|
title: splitEditorGroup(),
|
|
4336
4396
|
type: Button$2
|
|
@@ -4363,7 +4423,7 @@ const renderEmptyGroupCloseButton = (group, groupIndex) => {
|
|
|
4363
4423
|
childCount: 1,
|
|
4364
4424
|
className: EmptyGroupCloseButton,
|
|
4365
4425
|
'data-groupId': String(group.id),
|
|
4366
|
-
name:
|
|
4426
|
+
name: CloseGroup,
|
|
4367
4427
|
onClick: HandleClickAction,
|
|
4368
4428
|
title: closeEditorGroup(),
|
|
4369
4429
|
type: Button$2
|
|
@@ -4723,6 +4783,7 @@ const commandMap = {
|
|
|
4723
4783
|
'MainArea.loadContent': wrapCommand(loadContent),
|
|
4724
4784
|
'MainArea.newFile': wrapCommand(newFile),
|
|
4725
4785
|
'MainArea.openUri': wrapCommand(openUri),
|
|
4786
|
+
'MainArea.openUris': wrapCommand(openUris),
|
|
4726
4787
|
'MainArea.refresh': wrapCommand(refresh),
|
|
4727
4788
|
'MainArea.render2': render2,
|
|
4728
4789
|
'MainArea.renderEventListeners': renderEventListeners,
|