@lvce-editor/main-area-worker 9.53.0 → 9.54.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.
@@ -1217,7 +1217,8 @@ const create$4 = () => {
1217
1217
  const commandQueues = new Map();
1218
1218
  const generations = Object.create(null);
1219
1219
  const states = Object.create(null);
1220
- const commandMapRef = {};
1220
+ const commandMapRef = Object.create(null);
1221
+ const commandsById = Object.create(null);
1221
1222
  const getGeneration = uid => generations[uid] || 0;
1222
1223
  const isCurrentGeneration = (uid, generation) => {
1223
1224
  return states[uid] !== undefined && getGeneration(uid) === generation;
@@ -1279,6 +1280,18 @@ const create$4 = () => {
1279
1280
  delete states[key];
1280
1281
  }
1281
1282
  },
1283
+ createDirectEventCommandMap(requestRender) {
1284
+ return {
1285
+ async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
1286
+ const fn = commandsById[command];
1287
+ if (!fn) {
1288
+ throw new Error(`Viewlet command not found: ${command}`);
1289
+ }
1290
+ await fn(uid, ...args);
1291
+ await requestRender(uid);
1292
+ }
1293
+ };
1294
+ },
1282
1295
  diff(uid, modules, numbers) {
1283
1296
  const {
1284
1297
  oldState,
@@ -1310,6 +1323,9 @@ const create$4 = () => {
1310
1323
  },
1311
1324
  registerCommands(commandMap) {
1312
1325
  Object.assign(commandMapRef, commandMap);
1326
+ for (const [key, fn] of Object.entries(commandMap)) {
1327
+ commandsById[toCommandId(key)] = fn;
1328
+ }
1313
1329
  },
1314
1330
  set(uid, oldState, newState, scheduledState) {
1315
1331
  const current = states[uid];
@@ -3002,12 +3018,8 @@ const getPathEndIndex = pathName => {
3002
3018
  return Math.min(queryIndex, hashIndex);
3003
3019
  };
3004
3020
  const getPathName = uri => {
3005
- if (uri.startsWith('file://')) {
3006
- try {
3007
- return new URL(uri).pathname;
3008
- } catch {
3009
- return uri;
3010
- }
3021
+ if (uri.startsWith('file://') && URL.canParse(uri)) {
3022
+ return new URL(uri).pathname;
3011
3023
  }
3012
3024
  return uri;
3013
3025
  };
@@ -3029,20 +3041,16 @@ const hasBinaryFileSuffix = uri => {
3029
3041
  return binaryFileSuffixes.some(suffix => cleanPath.endsWith(suffix));
3030
3042
  };
3031
3043
  const getEditorInputFromUri = uri => {
3032
- if (uri.startsWith('diff://?')) {
3033
- try {
3034
- const parsed = new URL(uri);
3035
- const uriLeft = parsed.searchParams.get('left');
3036
- const uriRight = parsed.searchParams.get('right');
3037
- if (uriLeft && uriRight) {
3038
- return {
3039
- type: 'diff-editor',
3040
- uriLeft,
3041
- uriRight
3042
- };
3043
- }
3044
- } catch {
3045
- // Ignore malformed legacy URIs and fall back to a text editor input.
3044
+ if (uri.startsWith('diff://?') && URL.canParse(uri)) {
3045
+ const parsed = new URL(uri);
3046
+ const uriLeft = parsed.searchParams.get('left');
3047
+ const uriRight = parsed.searchParams.get('right');
3048
+ if (uriLeft && uriRight) {
3049
+ return {
3050
+ type: 'diff-editor',
3051
+ uriLeft,
3052
+ uriRight
3053
+ };
3046
3054
  }
3047
3055
  }
3048
3056
  if (uri.startsWith('extension-detail://')) {
@@ -3753,6 +3761,9 @@ const getLabel = uri => {
3753
3761
  if (uri.startsWith('running-extensions://')) {
3754
3762
  return 'Running Extensions';
3755
3763
  }
3764
+ if (uri.startsWith('cookie-import-view://')) {
3765
+ return 'Import Firefox Cookies';
3766
+ }
3756
3767
  if (uri.startsWith(inlineDiffPrefix)) {
3757
3768
  return getInlineDiffLabel(uri);
3758
3769
  }
@@ -5065,6 +5076,17 @@ const handleDragStart = state => {
5065
5076
  return state;
5066
5077
  };
5067
5078
 
5079
+ const resetPointerDown = state => {
5080
+ if (state.pointerDownGroupIndex === -1 && state.pointerDownTabIndex === -1) {
5081
+ return state;
5082
+ }
5083
+ return {
5084
+ ...state,
5085
+ pointerDownGroupIndex: -1,
5086
+ pointerDownTabIndex: -1
5087
+ };
5088
+ };
5089
+
5068
5090
  const openUrisWithContext = async (context, uris, reuseExisting = true) => {
5069
5091
  for (const uri of uris) {
5070
5092
  await openUriWithContext(context, {
@@ -5257,6 +5279,81 @@ const applyDropAction = async (context, action, splitDirection, targetGroupId) =
5257
5279
  }
5258
5280
  };
5259
5281
 
5282
+ const moveTabToGroup = (state, sourceGroupId, targetGroupId, tabId, targetIndex) => {
5283
+ const {
5284
+ layout
5285
+ } = state;
5286
+ const {
5287
+ groups
5288
+ } = layout;
5289
+ const sourceGroup = groups.find(group => group.id === sourceGroupId);
5290
+ const hasTargetGroup = groups.some(group => group.id === targetGroupId);
5291
+ if (!sourceGroup || !hasTargetGroup || sourceGroupId === targetGroupId) {
5292
+ return state;
5293
+ }
5294
+ const tabToMove = sourceGroup.tabs.find(tab => tab.id === tabId);
5295
+ if (!tabToMove) {
5296
+ return state;
5297
+ }
5298
+ const updatedGroups = groups.map(group => {
5299
+ if (group.id === sourceGroupId) {
5300
+ const newTabs = group.tabs.filter(tab => tab.id !== tabId);
5301
+ let newActiveTabId = group.activeTabId;
5302
+ if (group.activeTabId === tabId) {
5303
+ if (newTabs.length > 0) {
5304
+ const removedIndex = group.tabs.findIndex(tab => tab.id === tabId);
5305
+ newActiveTabId = newTabs[Math.min(removedIndex, newTabs.length - 1)].id;
5306
+ } else {
5307
+ newActiveTabId = -1;
5308
+ }
5309
+ }
5310
+ return {
5311
+ ...group,
5312
+ activeTabId: newActiveTabId,
5313
+ isEmpty: newTabs.length === 0,
5314
+ tabs: newTabs
5315
+ };
5316
+ }
5317
+ if (group.id === targetGroupId) {
5318
+ const insertIndex = group.tabs.length ;
5319
+ const newTabs = [...group.tabs];
5320
+ newTabs.splice(insertIndex, 0, tabToMove);
5321
+ return {
5322
+ ...group,
5323
+ activeTabId: tabId,
5324
+ isEmpty: newTabs.length === 0,
5325
+ tabs: newTabs
5326
+ };
5327
+ }
5328
+ return group;
5329
+ });
5330
+ return {
5331
+ ...state,
5332
+ layout: {
5333
+ ...layout,
5334
+ activeGroupId: targetGroupId,
5335
+ groups: updatedGroups
5336
+ }
5337
+ };
5338
+ };
5339
+
5340
+ const getOpenTabCount = state => {
5341
+ return state.layout.groups.reduce((count, group) => count + group.tabs.length, 0);
5342
+ };
5343
+ const applyTabDrop = (state, sourceGroupId, tabId, splitDirection, targetGroupId) => {
5344
+ if (targetGroupId === undefined) {
5345
+ return state;
5346
+ }
5347
+ if (splitDirection === None) {
5348
+ return moveTabToGroup(state, sourceGroupId, targetGroupId, tabId);
5349
+ }
5350
+ if (getOpenTabCount(state) === 1) {
5351
+ return state;
5352
+ }
5353
+ const splitState = splitForDrop(state, splitDirection, targetGroupId);
5354
+ return moveTabToGroup(splitState, sourceGroupId, splitState.layout.activeGroupId, tabId);
5355
+ };
5356
+
5260
5357
  const getDropAction = async uris => {
5261
5358
  for (const uri of uris) {
5262
5359
  if (uri.endsWith('/') || (await isDirectoryEditorInput({
@@ -5281,11 +5378,21 @@ const getDropAction = async uris => {
5281
5378
  };
5282
5379
  };
5283
5380
 
5381
+ const normalizeUri = uri => {
5382
+ return uri.startsWith('/') ? `file://${uri}` : uri;
5383
+ };
5284
5384
  const handleDrop = async (context, dropIdOrItemIds) => {
5385
+ const initialState = context.getState();
5386
+ const {
5387
+ pointerDownGroupIndex,
5388
+ pointerDownTabIndex
5389
+ } = initialState;
5390
+ const sourceGroup = initialState.layout.groups[pointerDownGroupIndex];
5391
+ const draggedTab = sourceGroup?.tabs[pointerDownTabIndex];
5285
5392
  const {
5286
5393
  splitDirection = None,
5287
5394
  targetGroupId
5288
- } = context.getState().dragOverlay ?? {};
5395
+ } = initialState.dragOverlay ?? {};
5289
5396
  await context.updateState(handleDragLeave);
5290
5397
  const {
5291
5398
  platform
@@ -5300,6 +5407,10 @@ const handleDrop = async (context, dropIdOrItemIds) => {
5300
5407
  } = await getDroppedItems(dropIdOrItemIds, isElectron);
5301
5408
  uris = droppedUris;
5302
5409
  }
5410
+ if (draggedTab?.uri && uris.length === 1 && normalizeUri(uris[0]) === normalizeUri(draggedTab.uri)) {
5411
+ await context.updateState(state => resetPointerDown(applyTabDrop(state, sourceGroup.id, draggedTab.id, splitDirection, targetGroupId)));
5412
+ return;
5413
+ }
5303
5414
  const actions = await getDropAction(uris);
5304
5415
  await applyDropAction(context, actions, splitDirection, targetGroupId);
5305
5416
  };
@@ -7556,6 +7667,9 @@ const renderTabIcon = tab => {
7556
7667
  if (tab.uri?.startsWith(SearchEditorScheme)) {
7557
7668
  return renderMaskIcon(MaskIconSearch);
7558
7669
  }
7670
+ if (!tab.icon) {
7671
+ return [];
7672
+ }
7559
7673
  return [{
7560
7674
  childCount: 0,
7561
7675
  className: TabIcon,
@@ -7566,6 +7680,7 @@ const renderTabIcon = tab => {
7566
7680
  };
7567
7681
  const renderTab = (tab, isActive, tabIndex, groupIndex) => {
7568
7682
  const closeButtonNodes = renderTabActions(tab.isDirty, tabIndex, groupIndex);
7683
+ const tabIconNodes = renderTabIcon(tab);
7569
7684
  let className = MainTab;
7570
7685
  if (isActive) {
7571
7686
  className = mergeClassNames(className, MainTabSelected);
@@ -7578,7 +7693,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
7578
7693
  }
7579
7694
  return [{
7580
7695
  'aria-selected': isActive,
7581
- childCount: 3,
7696
+ childCount: 2 + (tabIconNodes.length > 0 ? 1 : 0),
7582
7697
  className,
7583
7698
  'data-groupIndex': groupIndex,
7584
7699
  'data-index': tabIndex,
@@ -7594,7 +7709,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
7594
7709
  tabIndex: isActive ? 0 : -1,
7595
7710
  title: tab.uriTitle || tab.uri || tab.title,
7596
7711
  type: Div
7597
- }, ...renderTabIcon(tab), tabTitleNode, text(tab.title), ...closeButtonNodes];
7712
+ }, ...tabIconNodes, tabTitleNode, text(tab.title), ...closeButtonNodes];
7598
7713
  };
7599
7714
 
7600
7715
  const getTabsVirtualDom = (group, groupIndex, tabsChildCount) => {
@@ -8186,17 +8301,6 @@ const reopenEditorWith = async (context, preferredEditorId) => {
8186
8301
  }
8187
8302
  };
8188
8303
 
8189
- const resetPointerDown = state => {
8190
- if (state.pointerDownGroupIndex === -1 && state.pointerDownTabIndex === -1) {
8191
- return state;
8192
- }
8193
- return {
8194
- ...state,
8195
- pointerDownGroupIndex: -1,
8196
- pointerDownTabIndex: -1
8197
- };
8198
- };
8199
-
8200
8304
  const resize$1 = (state, dimensions) => {
8201
8305
  return {
8202
8306
  ...state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.53.0",
3
+ "version": "9.54.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",