@lvce-editor/title-bar-worker 4.1.0 → 4.3.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.
@@ -1238,139 +1238,74 @@ const Backslash = 'Backslash';
1238
1238
  const Star = '*';
1239
1239
  const Plus = '+';
1240
1240
 
1241
+ const keyCodeStringMap = {
1242
+ [Backquote$1]: Backquote,
1243
+ [Backslash$1]: Backslash,
1244
+ [Backspace$1]: Backspace,
1245
+ [Comma$1]: Comma,
1246
+ [Delete$1]: Delete,
1247
+ [Digit0$1]: Digit0,
1248
+ [Digit1$1]: Digit1,
1249
+ [Digit2$1]: Digit2,
1250
+ [Digit3$1]: Digit3,
1251
+ [Digit4$1]: Digit4,
1252
+ [Digit5$1]: Digit5,
1253
+ [Digit6$1]: Digit6,
1254
+ [Digit7$1]: Digit7,
1255
+ [Digit8$1]: Digit8,
1256
+ [Digit9$1]: Digit9,
1257
+ [DownArrow$1]: DownArrow,
1258
+ [End$1]: End,
1259
+ [Enter$1]: Enter,
1260
+ [Equal$1]: Equal,
1261
+ [Escape$1]: Escape,
1262
+ [F1$1]: F1,
1263
+ [F2$1]: F2,
1264
+ [F3$1]: F3,
1265
+ [F4$1]: F4,
1266
+ [F5$1]: F5,
1267
+ [F6$1]: F6,
1268
+ [Home$1]: Home,
1269
+ [Insert$1]: Insert,
1270
+ [KeyA$1]: KeyA,
1271
+ [KeyB$1]: KeyB,
1272
+ [KeyC$1]: KeyC,
1273
+ [KeyD$1]: KeyD,
1274
+ [KeyE$1]: KeyE,
1275
+ [KeyF$1]: KeyF,
1276
+ [KeyG$1]: KeyG,
1277
+ [KeyH$1]: KeyH,
1278
+ [KeyI$1]: KeyI,
1279
+ [KeyJ$1]: KeyJ,
1280
+ [KeyK$1]: KeyK,
1281
+ [KeyL$1]: KeyL,
1282
+ [KeyM$1]: KeyM,
1283
+ [KeyN$1]: KeyN,
1284
+ [KeyO$1]: KeyO,
1285
+ [KeyP$1]: KeyP,
1286
+ [KeyQ$1]: KeyQ,
1287
+ [KeyR$1]: KeyR,
1288
+ [KeyS$1]: KeyS,
1289
+ [KeyT$1]: KeyT,
1290
+ [KeyU$1]: KeyU,
1291
+ [KeyV$1]: KeyV,
1292
+ [KeyW$1]: KeyW,
1293
+ [KeyX$1]: KeyX,
1294
+ [KeyY$1]: KeyY,
1295
+ [KeyZ$1]: KeyZ,
1296
+ [LeftArrow$1]: LeftArrow,
1297
+ [Minus$1]: Minus,
1298
+ [PageDown$1]: PageDown,
1299
+ [PageUp$1]: PageUp,
1300
+ [Plus$1]: Plus,
1301
+ [RightArrow$1]: RightArrow,
1302
+ [Space$1]: Space,
1303
+ [Star$1]: Star,
1304
+ [Tab$1]: Tab,
1305
+ [UpArrow$1]: UpArrow
1306
+ };
1241
1307
  const getKeyCodeString = keyCode => {
1242
- switch (keyCode) {
1243
- case Backquote$1:
1244
- return Backquote;
1245
- case Backslash$1:
1246
- return Backslash;
1247
- case Backspace$1:
1248
- return Backspace;
1249
- case Comma$1:
1250
- return Comma;
1251
- case Delete$1:
1252
- return Delete;
1253
- case Digit0$1:
1254
- return Digit0;
1255
- case Digit1$1:
1256
- return Digit1;
1257
- case Digit2$1:
1258
- return Digit2;
1259
- case Digit3$1:
1260
- return Digit3;
1261
- case Digit4$1:
1262
- return Digit4;
1263
- case Digit5$1:
1264
- return Digit5;
1265
- case Digit6$1:
1266
- return Digit6;
1267
- case Digit7$1:
1268
- return Digit7;
1269
- case Digit8$1:
1270
- return Digit8;
1271
- case Digit9$1:
1272
- return Digit9;
1273
- case DownArrow$1:
1274
- return DownArrow;
1275
- case End$1:
1276
- return End;
1277
- case Enter$1:
1278
- return Enter;
1279
- case Equal$1:
1280
- return Equal;
1281
- case Escape$1:
1282
- return Escape;
1283
- case F1$1:
1284
- return F1;
1285
- case F2$1:
1286
- return F2;
1287
- case F3$1:
1288
- return F3;
1289
- case F4$1:
1290
- return F4;
1291
- case F5$1:
1292
- return F5;
1293
- case F6$1:
1294
- return F6;
1295
- case Home$1:
1296
- return Home;
1297
- case Insert$1:
1298
- return Insert;
1299
- case KeyA$1:
1300
- return KeyA;
1301
- case KeyB$1:
1302
- return KeyB;
1303
- case KeyC$1:
1304
- return KeyC;
1305
- case KeyD$1:
1306
- return KeyD;
1307
- case KeyE$1:
1308
- return KeyE;
1309
- case KeyF$1:
1310
- return KeyF;
1311
- case KeyG$1:
1312
- return KeyG;
1313
- case KeyH$1:
1314
- return KeyH;
1315
- case KeyI$1:
1316
- return KeyI;
1317
- case KeyJ$1:
1318
- return KeyJ;
1319
- case KeyK$1:
1320
- return KeyK;
1321
- case KeyL$1:
1322
- return KeyL;
1323
- case KeyM$1:
1324
- return KeyM;
1325
- case KeyN$1:
1326
- return KeyN;
1327
- case KeyO$1:
1328
- return KeyO;
1329
- case KeyP$1:
1330
- return KeyP;
1331
- case KeyQ$1:
1332
- return KeyQ;
1333
- case KeyR$1:
1334
- return KeyR;
1335
- case KeyS$1:
1336
- return KeyS;
1337
- case KeyT$1:
1338
- return KeyT;
1339
- case KeyU$1:
1340
- return KeyU;
1341
- case KeyV$1:
1342
- return KeyV;
1343
- case KeyW$1:
1344
- return KeyW;
1345
- case KeyX$1:
1346
- return KeyX;
1347
- case KeyY$1:
1348
- return KeyY;
1349
- case KeyZ$1:
1350
- return KeyZ;
1351
- case LeftArrow$1:
1352
- return LeftArrow;
1353
- case Minus$1:
1354
- return Minus;
1355
- case PageDown$1:
1356
- return PageDown;
1357
- case PageUp$1:
1358
- return PageUp;
1359
- case Plus$1:
1360
- return Plus;
1361
- case RightArrow$1:
1362
- return RightArrow;
1363
- case Space$1:
1364
- return Space;
1365
- case Star$1:
1366
- return Star;
1367
- case Tab$1:
1368
- return Tab;
1369
- case UpArrow$1:
1370
- return UpArrow;
1371
- default:
1372
- return Unknown;
1373
- }
1308
+ return keyCodeStringMap[keyCode] || Unknown;
1374
1309
  };
1375
1310
 
1376
1311
  const CtrlCmd = 1 << 11 >>> 0;
@@ -1456,13 +1391,13 @@ const create$1 = () => {
1456
1391
  },
1457
1392
  diff(uid, modules, numbers) {
1458
1393
  const {
1459
- newState,
1460
- oldState
1394
+ oldState,
1395
+ scheduledState
1461
1396
  } = states[uid];
1462
1397
  const diffResult = [];
1463
1398
  for (let i = 0; i < modules.length; i++) {
1464
1399
  const fn = modules[i];
1465
- if (!fn(oldState, newState)) {
1400
+ if (!fn(oldState, scheduledState)) {
1466
1401
  diffResult.push(numbers[i]);
1467
1402
  }
1468
1403
  }
@@ -1480,17 +1415,16 @@ const create$1 = () => {
1480
1415
  return ids;
1481
1416
  },
1482
1417
  getKeys() {
1483
- return Object.keys(states).map(key => {
1484
- return Number.parseFloat(key);
1485
- });
1418
+ return Object.keys(states).map(Number);
1486
1419
  },
1487
1420
  registerCommands(commandMap) {
1488
1421
  Object.assign(commandMapRef, commandMap);
1489
1422
  },
1490
- set(uid, oldState, newState) {
1423
+ set(uid, oldState, newState, scheduledState) {
1491
1424
  states[uid] = {
1492
1425
  newState,
1493
- oldState
1426
+ oldState,
1427
+ scheduledState: scheduledState ?? newState
1494
1428
  };
1495
1429
  },
1496
1430
  wrapCommand(fn) {
@@ -1510,7 +1444,8 @@ const create$1 = () => {
1510
1444
  };
1511
1445
  states[uid] = {
1512
1446
  newState: latestNew,
1513
- oldState: latestOld.oldState
1447
+ oldState: latestOld.oldState,
1448
+ scheduledState: latestNew
1514
1449
  };
1515
1450
  };
1516
1451
  return wrapped;
@@ -1547,7 +1482,8 @@ const create$1 = () => {
1547
1482
  };
1548
1483
  states[uid] = {
1549
1484
  newState: latestNew,
1550
- oldState: latestOld.oldState
1485
+ oldState: latestOld.oldState,
1486
+ scheduledState: latestNew
1551
1487
  };
1552
1488
  return {
1553
1489
  error
@@ -1567,6 +1503,7 @@ const Remote = 3;
1567
1503
 
1568
1504
  const DEFAULT_UID = 1;
1569
1505
  const DEFAULT_APP_NAME = 'Lvce Editor';
1506
+ const DEFAULT_MAIN_AREA_UID$1 = 2;
1570
1507
  const createDefaultState = (uid = DEFAULT_UID) => ({
1571
1508
  appName: DEFAULT_APP_NAME,
1572
1509
  assetDir: '',
@@ -1585,6 +1522,7 @@ const createDefaultState = (uid = DEFAULT_UID) => ({
1585
1522
  labelLetterSpacing: 0,
1586
1523
  labelPadding: 8,
1587
1524
  layoutControlsEnabled: false,
1525
+ mainAreaUid: DEFAULT_MAIN_AREA_UID$1,
1588
1526
  menus: [],
1589
1527
  platform: Electron,
1590
1528
  title: '',
@@ -1635,7 +1573,6 @@ const i18nString = (key, placeholders = emptyObject) => {
1635
1573
  const About = 'About';
1636
1574
  const Appearance = 'Appearance';
1637
1575
  const Chat = 'Chat';
1638
- const CheckForUpdates = 'Check For Updates';
1639
1576
  const ClearRecentlyOpened = 'Clear Recently Opened';
1640
1577
  const Close = 'Close';
1641
1578
  const Exit = 'Exit';
@@ -1924,6 +1861,14 @@ const getMenuIds = () => {
1924
1861
  return [Edit$2, File$3, Go$2, Help$3, OpenRecent$1, Run$2, Selection$2, Terminal$2, TitleBar$3, View$2, MenuIdTitleBarContextMenu, TitleBarContextMenu];
1925
1862
  };
1926
1863
 
1864
+ const hasActiveTextEditor = async mainAreaUid => {
1865
+ try {
1866
+ return await invoke('Main.hasActiveTextEditor', mainAreaUid);
1867
+ } catch {
1868
+ return false;
1869
+ }
1870
+ };
1871
+
1927
1872
  const getMenuEntries$e = () => {
1928
1873
  return [];
1929
1874
  };
@@ -2046,6 +1991,7 @@ const getMenuEntries$c = () => {
2046
1991
  * @enum {string}
2047
1992
  */
2048
1993
  const UiStrings = {
1994
+ AutoSave: 'Auto Save',
2049
1995
  Exit: 'Exit',
2050
1996
  NewFile: 'New File',
2051
1997
  NewWindow: 'New Window',
@@ -2054,6 +2000,9 @@ const UiStrings = {
2054
2000
  OpenRecent: 'Open Recent',
2055
2001
  Save: 'Save',
2056
2002
  SaveAll: 'Save All'};
2003
+ const autoSave = () => {
2004
+ return i18nString(UiStrings.AutoSave);
2005
+ };
2057
2006
  const newFile = () => {
2058
2007
  return i18nString(UiStrings.NewFile);
2059
2008
  };
@@ -2090,7 +2039,25 @@ const Terminal = 14;
2090
2039
  const TitleBar$1 = 15;
2091
2040
  const View = 16;
2092
2041
 
2093
- const getMenuEntries$b = platform => {
2042
+ const getAutoSave = async () => {
2043
+ try {
2044
+ return await invoke('Preferences.get', 'files.autoSave');
2045
+ } catch {
2046
+ return 'off';
2047
+ }
2048
+ };
2049
+ const isAutoSaveEnabled = autoSave => {
2050
+ return autoSave !== 'off';
2051
+ };
2052
+ const getSaveFlags = hasActiveTextEditor => {
2053
+ if (hasActiveTextEditor) {
2054
+ return None;
2055
+ }
2056
+ return Disabled;
2057
+ };
2058
+ const getMenuEntries$b = async (platform, autoSave$1, hasActiveTextEditor = false) => {
2059
+ const autoSaveValue = autoSave$1 ?? (await getAutoSave());
2060
+ const saveFlags = getSaveFlags(hasActiveTextEditor);
2094
2061
  const entries = [{
2095
2062
  command: 'Main.newFile',
2096
2063
  flags: None,
@@ -2118,14 +2085,19 @@ const getMenuEntries$b = platform => {
2118
2085
  label: openRecent()
2119
2086
  }, menuEntrySeparator, {
2120
2087
  command: 'Main.save',
2121
- flags: None,
2088
+ flags: saveFlags,
2122
2089
  id: 'save',
2123
2090
  label: save()
2124
2091
  }, {
2125
2092
  command: 'Main.saveAll',
2126
- flags: None,
2093
+ flags: saveFlags,
2127
2094
  id: 'saveAll',
2128
2095
  label: saveAll()
2096
+ }, menuEntrySeparator, {
2097
+ command: 'Preferences.toggleAutoSave',
2098
+ flags: isAutoSaveEnabled(autoSaveValue) ? Checked : Unchecked,
2099
+ id: 'autoSave',
2100
+ label: autoSave()
2129
2101
  }];
2130
2102
  if (platform === Electron) {
2131
2103
  entries.push(menuEntrySeparator, {
@@ -2148,22 +2120,11 @@ const toggleDeveloperTools = () => {
2148
2120
  const openProcessExplorer = () => {
2149
2121
  return i18nString(OpenProcessExplorer);
2150
2122
  };
2151
- const checkForUpdates = () => {
2152
- return i18nString(CheckForUpdates);
2153
- };
2154
2123
  const about = () => {
2155
2124
  return i18nString(About);
2156
2125
  };
2157
2126
 
2158
- const isAutoUpdateSupported = platform => {
2159
- if (platform !== Electron) {
2160
- return false;
2161
- }
2162
- return false;
2163
- };
2164
-
2165
2127
  const getMenuEntries$9 = async platform => {
2166
- const autoUpdateSupported = isAutoUpdateSupported(platform);
2167
2128
  const entries = [];
2168
2129
  if (platform !== Web) {
2169
2130
  entries.push({
@@ -2178,14 +2139,6 @@ const getMenuEntries$9 = async platform => {
2178
2139
  label: openProcessExplorer()
2179
2140
  });
2180
2141
  }
2181
- if (autoUpdateSupported) {
2182
- entries.push(menuEntrySeparator, {
2183
- command: 'AutoUpdater.checkForUpdates',
2184
- flags: RestoreFocus,
2185
- id: 'checkForUpdates',
2186
- label: checkForUpdates()
2187
- });
2188
- }
2189
2142
  if (entries.length > 0) {
2190
2143
  entries.push(menuEntrySeparator);
2191
2144
  }
@@ -2198,20 +2151,37 @@ const getMenuEntries$9 = async platform => {
2198
2151
  return entries;
2199
2152
  };
2200
2153
 
2201
- const getRecentlyOpened = () => {
2202
- return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2203
- };
2204
-
2205
- const File = 'file://';
2206
-
2207
- const getTitle$1 = (homeDir, uri) => {
2208
- if (!uri) {
2154
+ const DriveLetterProtocolRegex = /^[a-zA-Z]:$/;
2155
+ const normalizeUri = value => {
2156
+ try {
2157
+ const url = new URL(value);
2158
+ if (DriveLetterProtocolRegex.test(url.protocol)) {
2159
+ return '';
2160
+ }
2161
+ return url.href;
2162
+ } catch {
2209
2163
  return '';
2210
2164
  }
2211
- if (uri.startsWith(File)) {
2212
- return uri.slice(File.length);
2165
+ };
2166
+ const getRecentlyOpened = async () => {
2167
+ const recentlyOpened = await invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2168
+ if (!Array.isArray(recentlyOpened)) {
2169
+ return [];
2213
2170
  }
2214
- return uri;
2171
+ const seen = new Set();
2172
+ const uniqueUris = [];
2173
+ for (const item of recentlyOpened) {
2174
+ if (typeof item !== 'string') {
2175
+ continue;
2176
+ }
2177
+ const uri = normalizeUri(item);
2178
+ if (!uri || seen.has(uri)) {
2179
+ continue;
2180
+ }
2181
+ seen.add(uri);
2182
+ uniqueUris.push(uri);
2183
+ }
2184
+ return uniqueUris;
2215
2185
  };
2216
2186
 
2217
2187
  const moreDot = () => {
@@ -2221,13 +2191,43 @@ const clearRecentlyOpened = () => {
2221
2191
  return i18nString(ClearRecentlyOpened);
2222
2192
  };
2223
2193
 
2224
- const getHomeDir = () => {
2225
- return '';
2194
+ const File = 'file://';
2195
+
2196
+ const HomeDirRegex = /^\/(?:home|Users)\/[^/]+/;
2197
+ const startsWithHomeDir = (homeDir, path) => {
2198
+ return path === homeDir || path.startsWith(`${homeDir}/`);
2199
+ };
2200
+ const getPath = uri => {
2201
+ if (uri.startsWith(File)) {
2202
+ return uri.slice(File.length);
2203
+ }
2204
+ return uri;
2205
+ };
2206
+ const getHomeDir = uri => {
2207
+ const path = getPath(uri);
2208
+ const match = HomeDirRegex.exec(path);
2209
+ return match?.[0] || '';
2210
+ };
2211
+ const getTitle$1 = (homeDir, uri) => {
2212
+ if (!uri) {
2213
+ return '';
2214
+ }
2215
+ const path = getPath(uri);
2216
+ if (path !== uri) {
2217
+ if (homeDir && startsWithHomeDir(homeDir, path)) {
2218
+ return `~${path.slice(homeDir.length)}`;
2219
+ }
2220
+ return path;
2221
+ }
2222
+ // TODO tree shake this out in web
2223
+ if (homeDir && startsWithHomeDir(homeDir, uri)) {
2224
+ return `~${uri.slice(homeDir.length)}`;
2225
+ }
2226
+ return uri;
2226
2227
  };
2227
2228
 
2228
- const MAX_MENU_RECENT_ENTRIES = 10;
2229
2229
  const toMenuItem = folder => {
2230
- const homeDir = getHomeDir();
2230
+ const homeDir = getHomeDir(folder);
2231
2231
  const label = getTitle$1(homeDir, folder);
2232
2232
  return {
2233
2233
  args: [folder],
@@ -2236,6 +2236,8 @@ const toMenuItem = folder => {
2236
2236
  label
2237
2237
  };
2238
2238
  };
2239
+
2240
+ const MAX_MENU_RECENT_ENTRIES = 10;
2239
2241
  const getMenuEntries$8 = async () => {
2240
2242
  const allItems = await getRecentlyOpened();
2241
2243
  const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
@@ -2514,12 +2516,13 @@ const getMenuEntries$1 = () => {
2514
2516
  }];
2515
2517
  };
2516
2518
 
2519
+ const DEFAULT_MAIN_AREA_UID = 2;
2517
2520
  const getMenuEntries2 = async (state, props) => {
2518
2521
  switch (props.menuId) {
2519
2522
  case Edit$2:
2520
2523
  return getMenuEntries$d();
2521
2524
  case File$3:
2522
- return getMenuEntries$b(props.platform);
2525
+ return getMenuEntries$b(props.platform, undefined, await hasActiveTextEditor(state.mainAreaUid ?? DEFAULT_MAIN_AREA_UID));
2523
2526
  case Go$2:
2524
2527
  return getMenuEntries$a();
2525
2528
  case Help$3:
@@ -2945,14 +2948,7 @@ const CONTEXT_MENU_PADDING = 8;
2945
2948
  const getMenuHeight = items => {
2946
2949
  let height = CONTEXT_MENU_PADDING;
2947
2950
  for (const item of items) {
2948
- switch (item.flags) {
2949
- case Separator$1:
2950
- height += CONTEXT_MENU_SEPARATOR_HEIGHT;
2951
- break;
2952
- default:
2953
- height += CONTEXT_MENU_ITEM_HEIGHT;
2954
- break;
2955
- }
2951
+ height += item.flags === Separator$1 ? CONTEXT_MENU_SEPARATOR_HEIGHT : CONTEXT_MENU_ITEM_HEIGHT;
2956
2952
  }
2957
2953
  return height;
2958
2954
  };
@@ -2997,7 +2993,7 @@ const getIndexToFocusPreviousStartingAt = (items, startIndex) => {
2997
2993
  return -1;
2998
2994
  };
2999
2995
  const getIndexToFocusPrevious = menu => {
3000
- const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
2996
+ const startIndex = (menu.focusedIndex === -1 ? menu.items.length : menu.focusedIndex) - 1;
3001
2997
  return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
3002
2998
  };
3003
2999
  const canBeFocused = item => {
@@ -3174,7 +3170,7 @@ const handleTitleBarContextMenu = async state => {
3174
3170
  * @returns The parsed title string
3175
3171
  */
3176
3172
  const parseTitleTemplate = (template, folderName, appName) => {
3177
- return template.replaceAll('${folderName}', folderName).replaceAll('${appName}', appName);
3173
+ return template.replaceAll('${folderName}', () => folderName).replaceAll('${appName}', () => appName);
3178
3174
  };
3179
3175
 
3180
3176
  const getTitle = (workspaceUri, titleTemplate, appName) => {
@@ -3319,7 +3315,7 @@ const loadContent2 = async state => {
3319
3315
 
3320
3316
  // TODO load preferences here
3321
3317
 
3322
- if (titleBarStyleCustom === false && platform === Electron$1) {
3318
+ if (!titleBarStyleCustom && platform === Electron$1) {
3323
3319
  return hydrate(state);
3324
3320
  }
3325
3321
  return {
@@ -3979,7 +3975,7 @@ const next = (items, index) => {
3979
3975
  return (index + 1) % items.length;
3980
3976
  };
3981
3977
  const previous = (items, index) => {
3982
- return index === 0 ? items.length - 1 : index - 1;
3978
+ return (index === 0 ? items.length : index) - 1;
3983
3979
  };
3984
3980
 
3985
3981
  const focusFirst = state => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",