@lvce-editor/title-bar-worker 3.12.0 → 3.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/titleBarWorkerMain.js +146 -53
- package/package.json +1 -1
|
@@ -523,7 +523,7 @@ const callbacks = Object.create(null);
|
|
|
523
523
|
const get$2 = id => {
|
|
524
524
|
return callbacks[id];
|
|
525
525
|
};
|
|
526
|
-
const remove = id => {
|
|
526
|
+
const remove$1 = id => {
|
|
527
527
|
delete callbacks[id];
|
|
528
528
|
};
|
|
529
529
|
class JsonRpcError extends Error {
|
|
@@ -676,7 +676,7 @@ const resolve = (id, response) => {
|
|
|
676
676
|
return;
|
|
677
677
|
}
|
|
678
678
|
fn(response);
|
|
679
|
-
remove(id);
|
|
679
|
+
remove$1(id);
|
|
680
680
|
};
|
|
681
681
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
682
682
|
const getErrorType = prettyError => {
|
|
@@ -1020,6 +1020,25 @@ const WebWorkerRpcClient = {
|
|
|
1020
1020
|
__proto__: null,
|
|
1021
1021
|
create: create$1$1
|
|
1022
1022
|
};
|
|
1023
|
+
const createMockRpc = ({
|
|
1024
|
+
commandMap
|
|
1025
|
+
}) => {
|
|
1026
|
+
const invocations = [];
|
|
1027
|
+
const invoke = (method, ...params) => {
|
|
1028
|
+
invocations.push([method, ...params]);
|
|
1029
|
+
const command = commandMap[method];
|
|
1030
|
+
if (!command) {
|
|
1031
|
+
throw new Error(`command ${method} not found`);
|
|
1032
|
+
}
|
|
1033
|
+
return command(...params);
|
|
1034
|
+
};
|
|
1035
|
+
const mockRpc = {
|
|
1036
|
+
invocations,
|
|
1037
|
+
invoke,
|
|
1038
|
+
invokeAndTransfer: invoke
|
|
1039
|
+
};
|
|
1040
|
+
return mockRpc;
|
|
1041
|
+
};
|
|
1023
1042
|
|
|
1024
1043
|
const ContentInfo = 'contentinfo';
|
|
1025
1044
|
const Menu$1 = 'menu';
|
|
@@ -1353,7 +1372,11 @@ const set$2 = (id, rpc) => {
|
|
|
1353
1372
|
const get$1 = id => {
|
|
1354
1373
|
return rpcs[id];
|
|
1355
1374
|
};
|
|
1375
|
+
const remove = id => {
|
|
1376
|
+
delete rpcs[id];
|
|
1377
|
+
};
|
|
1356
1378
|
|
|
1379
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1357
1380
|
const create$2 = rpcId => {
|
|
1358
1381
|
return {
|
|
1359
1382
|
async dispose() {
|
|
@@ -1372,6 +1395,18 @@ const create$2 = rpcId => {
|
|
|
1372
1395
|
// @ts-ignore
|
|
1373
1396
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1374
1397
|
},
|
|
1398
|
+
registerMockRpc(commandMap) {
|
|
1399
|
+
const mockRpc = createMockRpc({
|
|
1400
|
+
commandMap
|
|
1401
|
+
});
|
|
1402
|
+
set$2(rpcId, mockRpc);
|
|
1403
|
+
// @ts-ignore
|
|
1404
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1405
|
+
remove(rpcId);
|
|
1406
|
+
};
|
|
1407
|
+
// @ts-ignore
|
|
1408
|
+
return mockRpc;
|
|
1409
|
+
},
|
|
1375
1410
|
set(rpc) {
|
|
1376
1411
|
set$2(rpcId, rpc);
|
|
1377
1412
|
}
|
|
@@ -1417,42 +1452,68 @@ const create$1 = () => {
|
|
|
1417
1452
|
const states = Object.create(null);
|
|
1418
1453
|
const commandMapRef = {};
|
|
1419
1454
|
return {
|
|
1420
|
-
|
|
1421
|
-
|
|
1455
|
+
clear() {
|
|
1456
|
+
for (const key of Object.keys(states)) {
|
|
1457
|
+
delete states[key];
|
|
1458
|
+
}
|
|
1422
1459
|
},
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
};
|
|
1460
|
+
diff(uid, modules, numbers) {
|
|
1461
|
+
const {
|
|
1462
|
+
newState,
|
|
1463
|
+
oldState
|
|
1464
|
+
} = states[uid];
|
|
1465
|
+
const diffResult = [];
|
|
1466
|
+
for (let i = 0; i < modules.length; i++) {
|
|
1467
|
+
const fn = modules[i];
|
|
1468
|
+
if (!fn(oldState, newState)) {
|
|
1469
|
+
diffResult.push(numbers[i]);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return diffResult;
|
|
1428
1473
|
},
|
|
1429
1474
|
dispose(uid) {
|
|
1430
1475
|
delete states[uid];
|
|
1431
1476
|
},
|
|
1477
|
+
get(uid) {
|
|
1478
|
+
return states[uid];
|
|
1479
|
+
},
|
|
1480
|
+
getCommandIds() {
|
|
1481
|
+
const keys = Object.keys(commandMapRef);
|
|
1482
|
+
const ids = keys.map(toCommandId);
|
|
1483
|
+
return ids;
|
|
1484
|
+
},
|
|
1432
1485
|
getKeys() {
|
|
1433
1486
|
return Object.keys(states).map(key => {
|
|
1434
1487
|
return Number.parseInt(key);
|
|
1435
1488
|
});
|
|
1436
1489
|
},
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1490
|
+
registerCommands(commandMap) {
|
|
1491
|
+
Object.assign(commandMapRef, commandMap);
|
|
1492
|
+
},
|
|
1493
|
+
set(uid, oldState, newState) {
|
|
1494
|
+
states[uid] = {
|
|
1495
|
+
newState,
|
|
1496
|
+
oldState
|
|
1497
|
+
};
|
|
1441
1498
|
},
|
|
1442
1499
|
wrapCommand(fn) {
|
|
1443
1500
|
const wrapped = async (uid, ...args) => {
|
|
1444
1501
|
const {
|
|
1445
|
-
|
|
1446
|
-
|
|
1502
|
+
newState,
|
|
1503
|
+
oldState
|
|
1447
1504
|
} = states[uid];
|
|
1448
1505
|
const newerState = await fn(newState, ...args);
|
|
1449
1506
|
if (oldState === newerState || newState === newerState) {
|
|
1450
1507
|
return;
|
|
1451
1508
|
}
|
|
1452
|
-
const
|
|
1509
|
+
const latestOld = states[uid];
|
|
1510
|
+
const latestNew = {
|
|
1511
|
+
...latestOld.newState,
|
|
1512
|
+
...newerState
|
|
1513
|
+
};
|
|
1453
1514
|
states[uid] = {
|
|
1454
|
-
|
|
1455
|
-
|
|
1515
|
+
newState: latestNew,
|
|
1516
|
+
oldState: latestOld.oldState
|
|
1456
1517
|
};
|
|
1457
1518
|
};
|
|
1458
1519
|
return wrapped;
|
|
@@ -1465,28 +1526,6 @@ const create$1 = () => {
|
|
|
1465
1526
|
return fn(newState, ...args);
|
|
1466
1527
|
};
|
|
1467
1528
|
return wrapped;
|
|
1468
|
-
},
|
|
1469
|
-
diff(uid, modules, numbers) {
|
|
1470
|
-
const {
|
|
1471
|
-
oldState,
|
|
1472
|
-
newState
|
|
1473
|
-
} = states[uid];
|
|
1474
|
-
const diffResult = [];
|
|
1475
|
-
for (let i = 0; i < modules.length; i++) {
|
|
1476
|
-
const fn = modules[i];
|
|
1477
|
-
if (!fn(oldState, newState)) {
|
|
1478
|
-
diffResult.push(numbers[i]);
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
return diffResult;
|
|
1482
|
-
},
|
|
1483
|
-
getCommandIds() {
|
|
1484
|
-
const keys = Object.keys(commandMapRef);
|
|
1485
|
-
const ids = keys.map(toCommandId);
|
|
1486
|
-
return ids;
|
|
1487
|
-
},
|
|
1488
|
-
registerCommands(commandMap) {
|
|
1489
|
-
Object.assign(commandMapRef, commandMap);
|
|
1490
1529
|
}
|
|
1491
1530
|
};
|
|
1492
1531
|
};
|
|
@@ -1529,8 +1568,10 @@ const createDefaultState = (uid = DEFAULT_UID) => ({
|
|
|
1529
1568
|
titleBarMenuBarEnabled: true,
|
|
1530
1569
|
titleBarStyleCustom: true,
|
|
1531
1570
|
titleBarTitleEnabled: true,
|
|
1571
|
+
titleTemplate: '${folderName}',
|
|
1532
1572
|
uid,
|
|
1533
1573
|
width: 800,
|
|
1574
|
+
workspaceUri: '',
|
|
1534
1575
|
x: 0,
|
|
1535
1576
|
y: 0
|
|
1536
1577
|
});
|
|
@@ -1749,6 +1790,7 @@ const create3 = (id, uri, x, y, width, height, platform, controlsOverlayEnabled,
|
|
|
1749
1790
|
titleBarStyleCustom,
|
|
1750
1791
|
uid: id,
|
|
1751
1792
|
width,
|
|
1793
|
+
workspaceUri: '',
|
|
1752
1794
|
x,
|
|
1753
1795
|
y
|
|
1754
1796
|
};
|
|
@@ -1756,7 +1798,7 @@ const create3 = (id, uri, x, y, width, height, platform, controlsOverlayEnabled,
|
|
|
1756
1798
|
};
|
|
1757
1799
|
|
|
1758
1800
|
const isEqual$3 = (oldState, newState) => {
|
|
1759
|
-
return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
1801
|
+
return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen && oldState.title === newState.title && oldState.workspaceUri === newState.workspaceUri;
|
|
1760
1802
|
};
|
|
1761
1803
|
|
|
1762
1804
|
const isEqual$2 = (oldState, newState) => {
|
|
@@ -2909,6 +2951,55 @@ const handlePointerOver = (state, name) => {
|
|
|
2909
2951
|
return handleMouseOver(state, index);
|
|
2910
2952
|
};
|
|
2911
2953
|
|
|
2954
|
+
/**
|
|
2955
|
+
* Parses a title template string and replaces special variables with their values.
|
|
2956
|
+
* Supported variables:
|
|
2957
|
+
* - ${folderName} - The name of the workspace folder
|
|
2958
|
+
* - ${appName} - The name of the application
|
|
2959
|
+
*
|
|
2960
|
+
* @param template - The template string to parse
|
|
2961
|
+
* @param folderName - The name of the workspace folder
|
|
2962
|
+
* @param appName - The name of the application
|
|
2963
|
+
* @returns The parsed title string
|
|
2964
|
+
*/
|
|
2965
|
+
const parseTitleTemplate = (template, folderName, appName) => {
|
|
2966
|
+
return template.replaceAll('${folderName}', folderName).replaceAll('${appName}', appName);
|
|
2967
|
+
};
|
|
2968
|
+
|
|
2969
|
+
const getTitle = (workspaceUri, titleTemplate, appName) => {
|
|
2970
|
+
if (!workspaceUri) {
|
|
2971
|
+
return '';
|
|
2972
|
+
}
|
|
2973
|
+
const slashIndex = workspaceUri.lastIndexOf('/');
|
|
2974
|
+
if (slashIndex === -1) {
|
|
2975
|
+
return '';
|
|
2976
|
+
}
|
|
2977
|
+
const folderName = workspaceUri.slice(slashIndex + 1);
|
|
2978
|
+
|
|
2979
|
+
// If titleTemplate is empty, return folderName directly
|
|
2980
|
+
if (!titleTemplate) {
|
|
2981
|
+
return folderName;
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
// If titleTemplate doesn't contain variables, return the template itself
|
|
2985
|
+
if (!titleTemplate.includes('${')) {
|
|
2986
|
+
return titleTemplate;
|
|
2987
|
+
}
|
|
2988
|
+
return parseTitleTemplate(titleTemplate, folderName, appName);
|
|
2989
|
+
};
|
|
2990
|
+
|
|
2991
|
+
const APP_NAME$1 = 'Lvce Editor';
|
|
2992
|
+
|
|
2993
|
+
// TODO in the future, it could also be a multi-root workspace
|
|
2994
|
+
const handleWorkspaceChange = async (state, uri) => {
|
|
2995
|
+
const title = getTitle(uri, state.titleTemplate, APP_NAME$1);
|
|
2996
|
+
return {
|
|
2997
|
+
...state,
|
|
2998
|
+
title,
|
|
2999
|
+
workspaceUri: uri
|
|
3000
|
+
};
|
|
3001
|
+
};
|
|
3002
|
+
|
|
2912
3003
|
const hideCommandCenter = async state => {
|
|
2913
3004
|
return {
|
|
2914
3005
|
...state,
|
|
@@ -3008,18 +3099,11 @@ const addWidths = async (entries, labelPadding, fontWeight, fontSize, fontFamily
|
|
|
3008
3099
|
return withWidths;
|
|
3009
3100
|
};
|
|
3010
3101
|
|
|
3011
|
-
const
|
|
3012
|
-
|
|
3013
|
-
return '';
|
|
3014
|
-
}
|
|
3015
|
-
const slashIndex = workspaceUri.lastIndexOf('/');
|
|
3016
|
-
if (slashIndex === -1) {
|
|
3017
|
-
return '';
|
|
3018
|
-
}
|
|
3019
|
-
const baseName = workspaceUri.slice(slashIndex + 1);
|
|
3020
|
-
return baseName;
|
|
3102
|
+
const getWorkspaceUri = () => {
|
|
3103
|
+
return invoke('Workspace.getUri');
|
|
3021
3104
|
};
|
|
3022
3105
|
|
|
3106
|
+
const APP_NAME = 'Lvce Editor';
|
|
3023
3107
|
const loadContent2 = async state => {
|
|
3024
3108
|
const {
|
|
3025
3109
|
controlsOverlayEnabled,
|
|
@@ -3034,8 +3118,8 @@ const loadContent2 = async state => {
|
|
|
3034
3118
|
const titleBarEntries = await getMenuEntries$2(platform);
|
|
3035
3119
|
const withWidths = await addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
3036
3120
|
const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
|
|
3037
|
-
const workspaceUri = await
|
|
3038
|
-
const title = getTitle(workspaceUri);
|
|
3121
|
+
const workspaceUri = await getWorkspaceUri();
|
|
3122
|
+
const title = getTitle(workspaceUri, state.titleTemplate, APP_NAME);
|
|
3039
3123
|
const iconWidth = 30;
|
|
3040
3124
|
|
|
3041
3125
|
// TODO load preferences here
|
|
@@ -3638,6 +3722,13 @@ const setPlatform = (state, platform) => {
|
|
|
3638
3722
|
};
|
|
3639
3723
|
};
|
|
3640
3724
|
|
|
3725
|
+
const setTitleTemplate = (state, titleTemplate) => {
|
|
3726
|
+
return {
|
|
3727
|
+
...state,
|
|
3728
|
+
titleTemplate
|
|
3729
|
+
};
|
|
3730
|
+
};
|
|
3731
|
+
|
|
3641
3732
|
const showCommandCenter = async state => {
|
|
3642
3733
|
return {
|
|
3643
3734
|
...state,
|
|
@@ -4264,6 +4355,7 @@ const commandMap = {
|
|
|
4264
4355
|
'TitleBar.handleMouseOver': wrapCommand(handleMouseOver),
|
|
4265
4356
|
'TitleBar.handlePointerOut': wrapCommand(handlePointerOut),
|
|
4266
4357
|
'TitleBar.handlePointerOver': wrapCommand(handlePointerOver),
|
|
4358
|
+
'TitleBar.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
|
|
4267
4359
|
'TitleBar.hideCommandCenter': wrapCommand(hideCommandCenter),
|
|
4268
4360
|
'TitleBar.hideMenuBar': wrapCommand(hideMenuBar),
|
|
4269
4361
|
'TitleBar.hydrateElectronApplicationMenu': wrapCommand(hydrate),
|
|
@@ -4273,6 +4365,7 @@ const commandMap = {
|
|
|
4273
4365
|
'TitleBar.resize': wrapCommand(resize),
|
|
4274
4366
|
'TitleBar.saveState': wrapGetter(saveState),
|
|
4275
4367
|
'TitleBar.setPlatform': wrapCommand(setPlatform),
|
|
4368
|
+
'TitleBar.setTitleTemplate': wrapCommand(setTitleTemplate),
|
|
4276
4369
|
'TitleBar.showCommandCenter': wrapCommand(showCommandCenter),
|
|
4277
4370
|
'TitleBar.showMenuBar': wrapCommand(showMenuBar),
|
|
4278
4371
|
'TitleBar.terminate': terminate,
|