@lvce-editor/title-bar-worker 3.13.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 +85 -44
- package/package.json +1 -1
|
@@ -1452,42 +1452,68 @@ const create$1 = () => {
|
|
|
1452
1452
|
const states = Object.create(null);
|
|
1453
1453
|
const commandMapRef = {};
|
|
1454
1454
|
return {
|
|
1455
|
-
|
|
1456
|
-
|
|
1455
|
+
clear() {
|
|
1456
|
+
for (const key of Object.keys(states)) {
|
|
1457
|
+
delete states[key];
|
|
1458
|
+
}
|
|
1457
1459
|
},
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
};
|
|
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;
|
|
1463
1473
|
},
|
|
1464
1474
|
dispose(uid) {
|
|
1465
1475
|
delete states[uid];
|
|
1466
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
|
+
},
|
|
1467
1485
|
getKeys() {
|
|
1468
1486
|
return Object.keys(states).map(key => {
|
|
1469
1487
|
return Number.parseInt(key);
|
|
1470
1488
|
});
|
|
1471
1489
|
},
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1490
|
+
registerCommands(commandMap) {
|
|
1491
|
+
Object.assign(commandMapRef, commandMap);
|
|
1492
|
+
},
|
|
1493
|
+
set(uid, oldState, newState) {
|
|
1494
|
+
states[uid] = {
|
|
1495
|
+
newState,
|
|
1496
|
+
oldState
|
|
1497
|
+
};
|
|
1476
1498
|
},
|
|
1477
1499
|
wrapCommand(fn) {
|
|
1478
1500
|
const wrapped = async (uid, ...args) => {
|
|
1479
1501
|
const {
|
|
1480
|
-
|
|
1481
|
-
|
|
1502
|
+
newState,
|
|
1503
|
+
oldState
|
|
1482
1504
|
} = states[uid];
|
|
1483
1505
|
const newerState = await fn(newState, ...args);
|
|
1484
1506
|
if (oldState === newerState || newState === newerState) {
|
|
1485
1507
|
return;
|
|
1486
1508
|
}
|
|
1487
|
-
const
|
|
1509
|
+
const latestOld = states[uid];
|
|
1510
|
+
const latestNew = {
|
|
1511
|
+
...latestOld.newState,
|
|
1512
|
+
...newerState
|
|
1513
|
+
};
|
|
1488
1514
|
states[uid] = {
|
|
1489
|
-
|
|
1490
|
-
|
|
1515
|
+
newState: latestNew,
|
|
1516
|
+
oldState: latestOld.oldState
|
|
1491
1517
|
};
|
|
1492
1518
|
};
|
|
1493
1519
|
return wrapped;
|
|
@@ -1500,28 +1526,6 @@ const create$1 = () => {
|
|
|
1500
1526
|
return fn(newState, ...args);
|
|
1501
1527
|
};
|
|
1502
1528
|
return wrapped;
|
|
1503
|
-
},
|
|
1504
|
-
diff(uid, modules, numbers) {
|
|
1505
|
-
const {
|
|
1506
|
-
oldState,
|
|
1507
|
-
newState
|
|
1508
|
-
} = states[uid];
|
|
1509
|
-
const diffResult = [];
|
|
1510
|
-
for (let i = 0; i < modules.length; i++) {
|
|
1511
|
-
const fn = modules[i];
|
|
1512
|
-
if (!fn(oldState, newState)) {
|
|
1513
|
-
diffResult.push(numbers[i]);
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
return diffResult;
|
|
1517
|
-
},
|
|
1518
|
-
getCommandIds() {
|
|
1519
|
-
const keys = Object.keys(commandMapRef);
|
|
1520
|
-
const ids = keys.map(toCommandId);
|
|
1521
|
-
return ids;
|
|
1522
|
-
},
|
|
1523
|
-
registerCommands(commandMap) {
|
|
1524
|
-
Object.assign(commandMapRef, commandMap);
|
|
1525
1529
|
}
|
|
1526
1530
|
};
|
|
1527
1531
|
};
|
|
@@ -1564,6 +1568,7 @@ const createDefaultState = (uid = DEFAULT_UID) => ({
|
|
|
1564
1568
|
titleBarMenuBarEnabled: true,
|
|
1565
1569
|
titleBarStyleCustom: true,
|
|
1566
1570
|
titleBarTitleEnabled: true,
|
|
1571
|
+
titleTemplate: '${folderName}',
|
|
1567
1572
|
uid,
|
|
1568
1573
|
width: 800,
|
|
1569
1574
|
workspaceUri: '',
|
|
@@ -1793,7 +1798,7 @@ const create3 = (id, uri, x, y, width, height, platform, controlsOverlayEnabled,
|
|
|
1793
1798
|
};
|
|
1794
1799
|
|
|
1795
1800
|
const isEqual$3 = (oldState, newState) => {
|
|
1796
|
-
return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen && oldState.title === newState.title;
|
|
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;
|
|
1797
1802
|
};
|
|
1798
1803
|
|
|
1799
1804
|
const isEqual$2 = (oldState, newState) => {
|
|
@@ -2946,7 +2951,22 @@ const handlePointerOver = (state, name) => {
|
|
|
2946
2951
|
return handleMouseOver(state, index);
|
|
2947
2952
|
};
|
|
2948
2953
|
|
|
2949
|
-
|
|
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) => {
|
|
2950
2970
|
if (!workspaceUri) {
|
|
2951
2971
|
return '';
|
|
2952
2972
|
}
|
|
@@ -2954,13 +2974,25 @@ const getTitle = workspaceUri => {
|
|
|
2954
2974
|
if (slashIndex === -1) {
|
|
2955
2975
|
return '';
|
|
2956
2976
|
}
|
|
2957
|
-
const
|
|
2958
|
-
|
|
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);
|
|
2959
2989
|
};
|
|
2960
2990
|
|
|
2991
|
+
const APP_NAME$1 = 'Lvce Editor';
|
|
2992
|
+
|
|
2961
2993
|
// TODO in the future, it could also be a multi-root workspace
|
|
2962
2994
|
const handleWorkspaceChange = async (state, uri) => {
|
|
2963
|
-
const title = getTitle(uri);
|
|
2995
|
+
const title = getTitle(uri, state.titleTemplate, APP_NAME$1);
|
|
2964
2996
|
return {
|
|
2965
2997
|
...state,
|
|
2966
2998
|
title,
|
|
@@ -3071,6 +3103,7 @@ const getWorkspaceUri = () => {
|
|
|
3071
3103
|
return invoke('Workspace.getUri');
|
|
3072
3104
|
};
|
|
3073
3105
|
|
|
3106
|
+
const APP_NAME = 'Lvce Editor';
|
|
3074
3107
|
const loadContent2 = async state => {
|
|
3075
3108
|
const {
|
|
3076
3109
|
controlsOverlayEnabled,
|
|
@@ -3086,7 +3119,7 @@ const loadContent2 = async state => {
|
|
|
3086
3119
|
const withWidths = await addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
3087
3120
|
const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
|
|
3088
3121
|
const workspaceUri = await getWorkspaceUri();
|
|
3089
|
-
const title = getTitle(workspaceUri);
|
|
3122
|
+
const title = getTitle(workspaceUri, state.titleTemplate, APP_NAME);
|
|
3090
3123
|
const iconWidth = 30;
|
|
3091
3124
|
|
|
3092
3125
|
// TODO load preferences here
|
|
@@ -3689,6 +3722,13 @@ const setPlatform = (state, platform) => {
|
|
|
3689
3722
|
};
|
|
3690
3723
|
};
|
|
3691
3724
|
|
|
3725
|
+
const setTitleTemplate = (state, titleTemplate) => {
|
|
3726
|
+
return {
|
|
3727
|
+
...state,
|
|
3728
|
+
titleTemplate
|
|
3729
|
+
};
|
|
3730
|
+
};
|
|
3731
|
+
|
|
3692
3732
|
const showCommandCenter = async state => {
|
|
3693
3733
|
return {
|
|
3694
3734
|
...state,
|
|
@@ -4325,6 +4365,7 @@ const commandMap = {
|
|
|
4325
4365
|
'TitleBar.resize': wrapCommand(resize),
|
|
4326
4366
|
'TitleBar.saveState': wrapGetter(saveState),
|
|
4327
4367
|
'TitleBar.setPlatform': wrapCommand(setPlatform),
|
|
4368
|
+
'TitleBar.setTitleTemplate': wrapCommand(setTitleTemplate),
|
|
4328
4369
|
'TitleBar.showCommandCenter': wrapCommand(showCommandCenter),
|
|
4329
4370
|
'TitleBar.showMenuBar': wrapCommand(showMenuBar),
|
|
4330
4371
|
'TitleBar.terminate': terminate,
|