@lvce-editor/main-area-worker 9.37.5 → 9.37.6

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.
@@ -54,6 +54,61 @@ class VError extends Error {
54
54
  }
55
55
  }
56
56
 
57
+ class AssertionError extends Error {
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = 'AssertionError';
61
+ }
62
+ }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String$1 = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown = 8;
71
+ const getType = value => {
72
+ switch (typeof value) {
73
+ case 'number':
74
+ return Number$1;
75
+ case 'function':
76
+ return Function;
77
+ case 'string':
78
+ return String$1;
79
+ case 'object':
80
+ if (value === null) {
81
+ return Null;
82
+ }
83
+ if (Array.isArray(value)) {
84
+ return Array$1;
85
+ }
86
+ return Object$1;
87
+ case 'boolean':
88
+ return Boolean$1;
89
+ default:
90
+ return Unknown;
91
+ }
92
+ };
93
+ const object = value => {
94
+ const type = getType(value);
95
+ if (type !== Object$1) {
96
+ throw new AssertionError('expected value to be of type object');
97
+ }
98
+ };
99
+ const number = value => {
100
+ const type = getType(value);
101
+ if (type !== Number$1) {
102
+ throw new AssertionError('expected value to be of type number');
103
+ }
104
+ };
105
+ const string = value => {
106
+ const type = getType(value);
107
+ if (type !== String$1) {
108
+ throw new AssertionError('expected value to be of type string');
109
+ }
110
+ };
111
+
57
112
  const isMessagePort = value => {
58
113
  return value && value instanceof MessagePort;
59
114
  };
@@ -1074,41 +1129,6 @@ const create$b = async ({
1074
1129
  return rpc;
1075
1130
  };
1076
1131
 
1077
- const create$a = async ({
1078
- commandMap,
1079
- isMessagePortOpen = true,
1080
- messagePort
1081
- }) => {
1082
- // TODO create a commandMap per rpc instance
1083
- register(commandMap);
1084
- const rawIpc = await IpcParentWithMessagePort$1.create({
1085
- isMessagePortOpen,
1086
- messagePort
1087
- });
1088
- const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
1089
- handleIpc(ipc);
1090
- const rpc = createRpc(ipc);
1091
- messagePort.start();
1092
- return rpc;
1093
- };
1094
-
1095
- const create$9 = async ({
1096
- commandMap,
1097
- isMessagePortOpen,
1098
- send
1099
- }) => {
1100
- const {
1101
- port1,
1102
- port2
1103
- } = new MessageChannel();
1104
- await send(port1);
1105
- return create$a({
1106
- commandMap,
1107
- isMessagePortOpen,
1108
- messagePort: port2
1109
- });
1110
- };
1111
-
1112
1132
  const createSharedLazyRpc = factory => {
1113
1133
  let rpcPromise;
1114
1134
  const getOrCreate = () => {
@@ -1137,7 +1157,7 @@ const createSharedLazyRpc = factory => {
1137
1157
  };
1138
1158
  };
1139
1159
 
1140
- const create$8 = async ({
1160
+ const create$a = async ({
1141
1161
  commandMap,
1142
1162
  getPortTuple,
1143
1163
  send
@@ -1154,13 +1174,13 @@ const create$8 = async ({
1154
1174
  return rpc;
1155
1175
  };
1156
1176
 
1157
- const create$7 = async ({
1177
+ const create$9 = async ({
1158
1178
  commandMap,
1159
1179
  getPortTuple,
1160
1180
  send
1161
1181
  }) => {
1162
1182
  return createSharedLazyRpc(() => {
1163
- return create$8({
1183
+ return create$a({
1164
1184
  commandMap,
1165
1185
  getPortTuple,
1166
1186
  send
@@ -1168,13 +1188,48 @@ const create$7 = async ({
1168
1188
  });
1169
1189
  };
1170
1190
 
1191
+ const create$8 = async ({
1192
+ commandMap,
1193
+ isMessagePortOpen = true,
1194
+ messagePort
1195
+ }) => {
1196
+ // TODO create a commandMap per rpc instance
1197
+ register(commandMap);
1198
+ const rawIpc = await IpcParentWithMessagePort$1.create({
1199
+ isMessagePortOpen,
1200
+ messagePort
1201
+ });
1202
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
1203
+ handleIpc(ipc);
1204
+ const rpc = createRpc(ipc);
1205
+ messagePort.start();
1206
+ return rpc;
1207
+ };
1208
+
1209
+ const create$7 = async ({
1210
+ commandMap,
1211
+ isMessagePortOpen,
1212
+ send
1213
+ }) => {
1214
+ const {
1215
+ port1,
1216
+ port2
1217
+ } = new MessageChannel();
1218
+ await send(port1);
1219
+ return create$8({
1220
+ commandMap,
1221
+ isMessagePortOpen,
1222
+ messagePort: port2
1223
+ });
1224
+ };
1225
+
1171
1226
  const create$6 = async ({
1172
1227
  commandMap,
1173
1228
  isMessagePortOpen,
1174
1229
  send
1175
1230
  }) => {
1176
1231
  return createSharedLazyRpc(() => {
1177
- return create$9({
1232
+ return create$7({
1178
1233
  commandMap,
1179
1234
  isMessagePortOpen,
1180
1235
  send
@@ -1214,7 +1269,7 @@ const createMockRpc = ({
1214
1269
  };
1215
1270
 
1216
1271
  const rpcs = Object.create(null);
1217
- const set$5 = (id, rpc) => {
1272
+ const set$6 = (id, rpc) => {
1218
1273
  rpcs[id] = rpc;
1219
1274
  };
1220
1275
  const get$1 = id => {
@@ -1247,7 +1302,7 @@ const create$4 = rpcId => {
1247
1302
  const mockRpc = createMockRpc({
1248
1303
  commandMap
1249
1304
  });
1250
- set$5(rpcId, mockRpc);
1305
+ set$6(rpcId, mockRpc);
1251
1306
  // @ts-ignore
1252
1307
  mockRpc[Symbol.dispose] = () => {
1253
1308
  remove(rpcId);
@@ -1256,7 +1311,7 @@ const create$4 = rpcId => {
1256
1311
  return mockRpc;
1257
1312
  },
1258
1313
  set(rpc) {
1259
- set$5(rpcId, rpc);
1314
+ set$6(rpcId, rpc);
1260
1315
  }
1261
1316
  };
1262
1317
  };
@@ -1438,7 +1493,6 @@ const VirtualDomElements = {
1438
1493
  const Button$1 = 'event.button';
1439
1494
  const ClientX = 'event.clientX';
1440
1495
  const ClientY = 'event.clientY';
1441
- const DataTransferFiles = 'event.dataTransfer.files';
1442
1496
  const DataTransferFiles2 = 'event.dataTransfer.files2';
1443
1497
  const EventTargetClassName = 'event.target.className';
1444
1498
  const TargetName = 'event.target.name';
@@ -1453,11 +1507,11 @@ const Add$1 = 6;
1453
1507
  const NavigateChild$1 = 7;
1454
1508
  const NavigateParent$1 = 8;
1455
1509
 
1456
- const Web = 1;
1457
1510
  const Electron = 2;
1458
1511
 
1459
1512
  const ClipBoardWorker = 3400;
1460
1513
  const DialogWorker = 7014;
1514
+ const DragAndDropWorker = 3404;
1461
1515
  const IconThemeWorker = 7009;
1462
1516
  const RendererWorker = 1;
1463
1517
 
@@ -1468,17 +1522,25 @@ const SetPatches = 'Viewlet.setPatches';
1468
1522
  const FocusEditorText = 12;
1469
1523
 
1470
1524
  const {
1471
- invoke: invoke$3,
1472
- set: set$4
1525
+ invoke: invoke$4,
1526
+ set: set$5
1473
1527
  } = create$4(ClipBoardWorker);
1474
1528
  const writeText = async text => {
1475
- return invoke$3('ClipBoard.writeText', text);
1529
+ return invoke$4('ClipBoard.writeText', text);
1476
1530
  };
1477
1531
 
1532
+ const {
1533
+ invoke: invoke$3,
1534
+ set: set$4
1535
+ } = create$4(DialogWorker);
1536
+
1478
1537
  const {
1479
1538
  invoke: invoke$2,
1480
1539
  set: set$3
1481
- } = create$4(DialogWorker);
1540
+ } = create$4(DragAndDropWorker);
1541
+ const getDroppedItems = async (itemIds, isElectron) => {
1542
+ return invoke$2('DragAndDrop.getDroppedItems', itemIds, isElectron);
1543
+ };
1482
1544
 
1483
1545
  const {
1484
1546
  invoke: invoke$1,
@@ -1489,61 +1551,6 @@ const getIcons = async iconRequests => {
1489
1551
  return invoke$1('IconTheme.getIcons', iconRequests);
1490
1552
  };
1491
1553
 
1492
- class AssertionError extends Error {
1493
- constructor(message) {
1494
- super(message);
1495
- this.name = 'AssertionError';
1496
- }
1497
- }
1498
- const Object$1 = 1;
1499
- const Number$1 = 2;
1500
- const Array$1 = 3;
1501
- const String$1 = 4;
1502
- const Boolean$1 = 5;
1503
- const Function = 6;
1504
- const Null = 7;
1505
- const Unknown = 8;
1506
- const getType = value => {
1507
- switch (typeof value) {
1508
- case 'number':
1509
- return Number$1;
1510
- case 'function':
1511
- return Function;
1512
- case 'string':
1513
- return String$1;
1514
- case 'object':
1515
- if (value === null) {
1516
- return Null;
1517
- }
1518
- if (Array.isArray(value)) {
1519
- return Array$1;
1520
- }
1521
- return Object$1;
1522
- case 'boolean':
1523
- return Boolean$1;
1524
- default:
1525
- return Unknown;
1526
- }
1527
- };
1528
- const object = value => {
1529
- const type = getType(value);
1530
- if (type !== Object$1) {
1531
- throw new AssertionError('expected value to be of type object');
1532
- }
1533
- };
1534
- const number = value => {
1535
- const type = getType(value);
1536
- if (type !== Number$1) {
1537
- throw new AssertionError('expected value to be of type number');
1538
- }
1539
- };
1540
- const string = value => {
1541
- const type = getType(value);
1542
- if (type !== String$1) {
1543
- throw new AssertionError('expected value to be of type string');
1544
- }
1545
- };
1546
-
1547
1554
  const {
1548
1555
  invoke,
1549
1556
  invokeAndTransfer,
@@ -1559,14 +1566,14 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1559
1566
  number(y);
1560
1567
  await invoke('ContextMenu.show2', uid, menuId, x, y, args);
1561
1568
  };
1562
- const getFileHandles = async fileIds => {
1563
- const files = await invoke('FileSystemHandle.getFileHandles', fileIds);
1564
- return files;
1565
- };
1566
1569
  const sendMessagePortToClipBoardWorker$1 = async (port, rpcId) => {
1567
1570
  const command = 'ClipBoard.handleMessagePort';
1568
1571
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToClipBoardWorker', port, command, rpcId);
1569
1572
  };
1573
+ const sendMessagePortToDragAndDropWorker = async port => {
1574
+ const command = 'DragAndDrop.handleMessagePort';
1575
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDragAndDropWorker', port, command);
1576
+ };
1570
1577
  const sendMessagePortToDialogWorker = async port => {
1571
1578
  const command = 'HandleMessagePort.handleMessagePort';
1572
1579
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
@@ -2419,7 +2426,7 @@ const saveEditor = async editorUid => {
2419
2426
  const missingDialogWorkerRelay = 'Command "SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker" not found';
2420
2427
  const confirm = async (message, options) => {
2421
2428
  try {
2422
- return await invoke$2('ConfirmPrompt.prompt', message, options);
2429
+ return await invoke$3('ConfirmPrompt.prompt', message, options);
2423
2430
  } catch (error) {
2424
2431
  if (!String(error).includes(missingDialogWorkerRelay)) {
2425
2432
  throw error;
@@ -4249,7 +4256,7 @@ const openInputWithContext = async (context, options) => {
4249
4256
  const title = getEditorInputTitle(editorInput);
4250
4257
  const editorType = getEditorInputEditorType(editorInput);
4251
4258
  const currentState = state;
4252
- const existingTab = findTabByUri(currentState, uri);
4259
+ const existingTab = options.reuseExisting === false ? undefined : findTabByUri(currentState, uri);
4253
4260
  const shouldRetryExistingTab = !!existingTab && existingTab.tab.loadingState === 'error';
4254
4261
  if (existingTab && !shouldRetryExistingTab) {
4255
4262
  const switchedState = getExistingTabState(currentState, existingTab, preview);
@@ -4363,12 +4370,13 @@ const getViewletContext = (options, viewletContext) => {
4363
4370
  if (viewletContext !== undefined || typeof options === 'string') {
4364
4371
  return viewletContext;
4365
4372
  }
4366
- const context = Object.fromEntries(Object.entries(options).filter(([key]) => key !== 'focus' && key !== 'preview' && key !== 'uri'));
4373
+ const context = Object.fromEntries(Object.entries(options).filter(([key]) => key !== 'focus' && key !== 'preview' && key !== 'reuseExisting' && key !== 'uri'));
4367
4374
  return Object.keys(context).length === 0 ? undefined : context;
4368
4375
  };
4369
4376
  const getOpenInputOptions = (options, focus = true, viewletContext) => {
4370
4377
  const uri = getOptionUriOptions(options);
4371
4378
  const preview = typeof options === 'string' ? false : options.preview ?? false;
4379
+ const reuseExisting = typeof options === 'string' ? true : options.reuseExisting ?? true;
4372
4380
  const context = getViewletContext(options, viewletContext);
4373
4381
  return {
4374
4382
  ...(context !== undefined && {
@@ -4376,7 +4384,8 @@ const getOpenInputOptions = (options, focus = true, viewletContext) => {
4376
4384
  }),
4377
4385
  editorInput: getNormalizedOpenEditorInput(uri),
4378
4386
  focus: typeof options === 'string' ? focus : options.focus,
4379
- preview
4387
+ preview,
4388
+ reuseExisting
4380
4389
  };
4381
4390
  };
4382
4391
  const openUri = async (state, options, focus = true, viewletContext) => {
@@ -4763,6 +4772,7 @@ const getOverlay = (x, y, width, height, splitDirection) => {
4763
4772
  case Down:
4764
4773
  return {
4765
4774
  height: halfHeight,
4775
+ splitDirection,
4766
4776
  width,
4767
4777
  x,
4768
4778
  y: y + halfHeight
@@ -4770,6 +4780,7 @@ const getOverlay = (x, y, width, height, splitDirection) => {
4770
4780
  case Left:
4771
4781
  return {
4772
4782
  height,
4783
+ splitDirection,
4773
4784
  width: halfWidth,
4774
4785
  x,
4775
4786
  y
@@ -4777,6 +4788,7 @@ const getOverlay = (x, y, width, height, splitDirection) => {
4777
4788
  case Right:
4778
4789
  return {
4779
4790
  height,
4791
+ splitDirection,
4780
4792
  width: halfWidth,
4781
4793
  x: x + halfWidth,
4782
4794
  y
@@ -4784,6 +4796,7 @@ const getOverlay = (x, y, width, height, splitDirection) => {
4784
4796
  case Up:
4785
4797
  return {
4786
4798
  height: halfHeight,
4799
+ splitDirection,
4787
4800
  width,
4788
4801
  x,
4789
4802
  y
@@ -4791,6 +4804,7 @@ const getOverlay = (x, y, width, height, splitDirection) => {
4791
4804
  default:
4792
4805
  return {
4793
4806
  height,
4807
+ splitDirection,
4794
4808
  width,
4795
4809
  x,
4796
4810
  y
@@ -4841,7 +4855,7 @@ const getDragOverlay = (state, eventX, eventY) => {
4841
4855
  };
4842
4856
 
4843
4857
  const isEqual = (oldOverlay, newOverlay) => {
4844
- return oldOverlay?.x === newOverlay?.x && oldOverlay?.y === newOverlay?.y && oldOverlay?.width === newOverlay?.width && oldOverlay?.height === newOverlay?.height;
4858
+ return oldOverlay?.x === newOverlay?.x && oldOverlay?.y === newOverlay?.y && oldOverlay?.width === newOverlay?.width && oldOverlay?.height === newOverlay?.height && oldOverlay?.splitDirection === newOverlay?.splitDirection;
4845
4859
  };
4846
4860
  const handleDragOver = (state, eventX, eventY) => {
4847
4861
  const {
@@ -4857,139 +4871,229 @@ const handleDragOver = (state, eventX, eventY) => {
4857
4871
  };
4858
4872
  };
4859
4873
 
4860
- const chromiumDragIdRegex = /^[A-F\d]{32}$/i;
4861
- const isChromiumDragId = item => {
4862
- if (!item || typeof item !== 'object') {
4863
- return false;
4864
- }
4865
- const candidate = item;
4866
- return candidate.kind === 'string' && (candidate.type === '' || candidate.type === 'chromium/x-drag-id') && typeof candidate.value === 'string' && chromiumDragIdRegex.test(candidate.value);
4867
- };
4868
-
4869
- const isDroppedFileSystemHandle = item => {
4870
- if (!item || typeof item !== 'object') {
4871
- return false;
4872
- }
4873
- const candidate = item;
4874
- const handle = candidate.value;
4875
- return candidate.kind === 'file' && Boolean(handle) && typeof handle === 'object' && (handle.kind === 'directory' || handle.kind === 'file') && typeof handle.name === 'string';
4876
- };
4877
-
4878
- const isUriList = item => {
4879
- if (!item || typeof item !== 'object') {
4880
- return false;
4874
+ const openUrisWithContext = async (context, uris, reuseExisting = true) => {
4875
+ for (const uri of uris) {
4876
+ await openUriWithContext(context, {
4877
+ focus: true,
4878
+ reuseExisting,
4879
+ uri
4880
+ });
4881
4881
  }
4882
- const candidate = item;
4883
- return candidate.kind === 'string' && candidate.type === 'text/uri-list' && typeof candidate.value === 'string';
4884
- };
4885
-
4886
- const lineSeparatorRegex = /\r?\n/;
4887
- const parseUriList = value => {
4888
- return value.split(lineSeparatorRegex).map(uri => uri.trim()).filter(uri => uri && !uri.startsWith('#'));
4889
4882
  };
4890
4883
 
4891
- const suffixByHandleKind = {
4892
- directory: '/',
4893
- file: ''
4894
- };
4895
- const getDroppedBrowserUris = async itemIds => {
4896
- if (itemIds.length === 0) {
4897
- return [];
4898
- }
4899
- const items = await getFileHandles(itemIds);
4900
- let hasChromiumDragId = false;
4901
- const uris = [];
4902
- for (const [index, item] of items.entries()) {
4903
- if (isUriList(item)) {
4904
- uris.push(...parseUriList(item.value));
4905
- continue;
4906
- }
4907
- if (isChromiumDragId(item)) {
4908
- hasChromiumDragId = true;
4909
- continue;
4910
- }
4911
- if (!isDroppedFileSystemHandle(item)) {
4912
- continue;
4913
- }
4914
- const handle = item.value;
4915
- const suffix = suffixByHandleKind[handle.kind];
4916
- const uri = `html:///dropped-files/${Date.now()}/${itemIds[index]}/${handle.name}${suffix}`;
4917
- await invoke('PersistentFileHandle.addHandle', uri, handle);
4918
- uris.push(uri);
4919
- }
4920
- if (uris.length > 0 || !hasChromiumDragId) {
4921
- return uris;
4922
- }
4923
- const dragInfo = await invoke('Viewlet.getDragData');
4924
- if (!dragInfo || typeof dragInfo !== 'object' || !Array.isArray(dragInfo.items)) {
4925
- return uris;
4926
- }
4927
- for (const item of dragInfo.items) {
4928
- const candidate = item;
4929
- if (candidate.type === 'text/uri-list' && typeof candidate.data === 'string') {
4930
- uris.push(...parseUriList(candidate.data));
4931
- }
4932
- }
4933
- return uris;
4934
- };
4884
+ const splitDown$1 = (state, groupId) => {
4885
+ const {
4886
+ layout
4887
+ } = state;
4888
+ const {
4889
+ activeGroupId,
4890
+ direction,
4891
+ groups
4892
+ } = layout;
4935
4893
 
4936
- const windowsDriveLetterRegex = /^[a-zA-Z]:\\/;
4937
- const encodeFilePath = path => {
4938
- return encodeURI(path).replaceAll('#', '%23').replaceAll('?', '%3F');
4939
- };
4940
- const toFileUri$1 = path => {
4941
- if (path.startsWith('file://')) {
4942
- return path;
4894
+ // If there are no groups, create an initial empty group first
4895
+ if (groups.length === 0) {
4896
+ const initialGroupId = create$2();
4897
+ const initialGroup = {
4898
+ activeTabId: -1,
4899
+ direction,
4900
+ focused: true,
4901
+ id: initialGroupId,
4902
+ isEmpty: true,
4903
+ size: 100,
4904
+ tabs: []
4905
+ };
4906
+ const stateWithInitialGroup = {
4907
+ ...state,
4908
+ layout: {
4909
+ ...layout,
4910
+ activeGroupId: initialGroupId,
4911
+ groups: [initialGroup]
4912
+ }
4913
+ };
4914
+ return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, 'down');
4943
4915
  }
4944
- if (windowsDriveLetterRegex.test(path)) {
4945
- const normalizedPath = path.replaceAll('\\', '/');
4946
- return `file:///${encodeFilePath(normalizedPath)}`;
4916
+ const resolvedGroupId = groupId ?? activeGroupId;
4917
+ if (!resolvedGroupId) {
4918
+ return state;
4947
4919
  }
4948
- return `file://${encodeFilePath(path)}`;
4920
+ return splitEditorGroup$1(state, resolvedGroupId, 'down');
4949
4921
  };
4950
4922
 
4951
- const getDroppedElectronUris = async (itemIds, files) => {
4952
- if (itemIds.length > 0) {
4953
- await getFileHandles(itemIds);
4954
- }
4955
- const uris = [];
4956
- for (const file of files) {
4957
- const path = await invoke('FileSystemHandle.getFilePathElectron', file);
4958
- uris.push(toFileUri$1(path));
4923
+ const splitLeft$1 = (state, groupId) => {
4924
+ const {
4925
+ layout
4926
+ } = state;
4927
+ const {
4928
+ activeGroupId,
4929
+ direction,
4930
+ groups
4931
+ } = layout;
4932
+ if (groups.length === 0) {
4933
+ const initialGroupId = create$2();
4934
+ const initialGroup = {
4935
+ activeTabId: -1,
4936
+ direction,
4937
+ focused: true,
4938
+ id: initialGroupId,
4939
+ isEmpty: true,
4940
+ size: 100,
4941
+ tabs: []
4942
+ };
4943
+ const stateWithInitialGroup = {
4944
+ ...state,
4945
+ layout: {
4946
+ ...layout,
4947
+ activeGroupId: initialGroupId,
4948
+ groups: [initialGroup]
4949
+ }
4950
+ };
4951
+ return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, Left$1);
4959
4952
  }
4960
- return uris;
4953
+ const targetGroupId = groupId ?? (activeGroupId === -1 ? groups[0]?.id : activeGroupId) ?? 0;
4954
+ return splitEditorGroup$1(state, targetGroupId, Left$1);
4961
4955
  };
4962
4956
 
4963
- const getDroppedUris = async (itemIds, files = [], platform = Web) => {
4964
- if (platform === Electron && files.length > 0) {
4965
- return getDroppedElectronUris(itemIds, files);
4957
+ const splitRight$1 = (state, groupId) => {
4958
+ const {
4959
+ layout
4960
+ } = state;
4961
+ const {
4962
+ activeGroupId,
4963
+ direction,
4964
+ groups
4965
+ } = layout;
4966
+
4967
+ // If there are no groups, create an initial empty group first
4968
+ if (groups.length === 0) {
4969
+ const initialGroupId = create$2();
4970
+ const initialGroup = {
4971
+ activeTabId: -1,
4972
+ direction,
4973
+ focused: true,
4974
+ id: initialGroupId,
4975
+ isEmpty: true,
4976
+ size: 100,
4977
+ tabs: []
4978
+ };
4979
+ const stateWithInitialGroup = {
4980
+ ...state,
4981
+ layout: {
4982
+ ...layout,
4983
+ activeGroupId: initialGroupId,
4984
+ groups: [initialGroup]
4985
+ }
4986
+ };
4987
+ return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, Right$1);
4966
4988
  }
4967
- return getDroppedBrowserUris(itemIds);
4989
+ const targetGroupId = groupId ?? (activeGroupId === -1 ? groups[0]?.id : activeGroupId) ?? 0;
4990
+ return splitEditorGroup$1(state, targetGroupId, Right$1);
4968
4991
  };
4969
4992
 
4970
- const openUrisWithContext = async (context, uris) => {
4971
- for (const uri of uris) {
4972
- await openUriWithContext(context, uri);
4993
+ const splitUp$1 = (state, groupId) => {
4994
+ const {
4995
+ layout
4996
+ } = state;
4997
+ const {
4998
+ activeGroupId,
4999
+ direction,
5000
+ groups
5001
+ } = layout;
5002
+ if (groups.length === 0) {
5003
+ const initialGroupId = create$2();
5004
+ const initialGroup = {
5005
+ activeTabId: -1,
5006
+ direction,
5007
+ focused: true,
5008
+ id: initialGroupId,
5009
+ isEmpty: true,
5010
+ size: 100,
5011
+ tabs: []
5012
+ };
5013
+ const stateWithInitialGroup = {
5014
+ ...state,
5015
+ layout: {
5016
+ ...layout,
5017
+ activeGroupId: initialGroupId,
5018
+ groups: [initialGroup]
5019
+ }
5020
+ };
5021
+ return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, 'up');
4973
5022
  }
5023
+ const resolvedGroupId = groupId ?? activeGroupId;
5024
+ if (!resolvedGroupId) {
5025
+ return state;
5026
+ }
5027
+ return splitEditorGroup$1(state, resolvedGroupId, 'up');
4974
5028
  };
4975
5029
 
4976
- const handleDrop = async (context, itemIds, files = []) => {
4977
- await context.updateState(handleDragLeave);
4978
- const {
4979
- platform
4980
- } = context.getState();
4981
- const uris = await getDroppedUris(itemIds, files, platform);
5030
+ const splitForDrop = (state, splitDirection) => {
5031
+ switch (splitDirection) {
5032
+ case Down:
5033
+ return splitDown$1(state);
5034
+ case Left:
5035
+ return splitLeft$1(state);
5036
+ case Right:
5037
+ return splitRight$1(state);
5038
+ case Up:
5039
+ return splitUp$1(state);
5040
+ default:
5041
+ return state;
5042
+ }
5043
+ };
5044
+ const getDropAction = async uris => {
4982
5045
  for (const uri of uris) {
4983
5046
  if (uri.endsWith('/') || (await isDirectoryEditorInput({
4984
5047
  type: 'editor',
4985
5048
  uri
4986
5049
  }))) {
4987
- const command = uri.startsWith('file://') ? 'Workspace.setUri' : 'Workspace.setPath';
4988
- void invoke(command, uri).catch(() => {});
4989
- return;
5050
+ if (uri.startsWith('file://')) {
5051
+ return {
5052
+ command: 'setUri',
5053
+ value: uri
5054
+ };
5055
+ }
5056
+ return {
5057
+ command: 'setPath',
5058
+ value: uri
5059
+ };
4990
5060
  }
4991
5061
  }
4992
- await openUrisWithContext(context, uris);
5062
+ return {
5063
+ command: 'openFiles',
5064
+ uris
5065
+ };
5066
+ };
5067
+ const applyDropAction = async (context, action, splitDirection) => {
5068
+ switch (action.command) {
5069
+ case 'openFiles':
5070
+ {
5071
+ if (action.uris.length > 0 && splitDirection !== None) {
5072
+ await context.updateState(state => splitForDrop(state, splitDirection));
5073
+ }
5074
+ await openUrisWithContext(context, action.uris, splitDirection === None);
5075
+ break;
5076
+ }
5077
+ case 'setPath':
5078
+ void invoke('Workspace.setPath', action.value).catch(() => {});
5079
+ break;
5080
+ case 'setUri':
5081
+ void invoke('Workspace.setUri', action.value).catch(() => {});
5082
+ break;
5083
+ }
5084
+ };
5085
+ const handleDrop = async (context, itemIds) => {
5086
+ const splitDirection = context.getState().dragOverlay?.splitDirection ?? None;
5087
+ await context.updateState(handleDragLeave);
5088
+ const {
5089
+ platform
5090
+ } = context.getState();
5091
+ const isElectron = platform === Electron;
5092
+ const {
5093
+ uris
5094
+ } = await getDroppedItems(itemIds, isElectron);
5095
+ const actions = await getDropAction(uris);
5096
+ await applyDropAction(context, actions, splitDirection);
4993
5097
  };
4994
5098
 
4995
5099
  const EditorGroupHeader = 'EditorGroupHeader';
@@ -6024,16 +6128,16 @@ const Retry = 'Retry';
6024
6128
  const openFile = () => {
6025
6129
  return i18nString(OpenFile);
6026
6130
  };
6027
- const splitUp$1 = () => {
6131
+ const splitUp = () => {
6028
6132
  return i18nString(SplitUp);
6029
6133
  };
6030
- const splitDown$1 = () => {
6134
+ const splitDown = () => {
6031
6135
  return i18nString(SplitDown);
6032
6136
  };
6033
- const splitLeft$1 = () => {
6137
+ const splitLeft = () => {
6034
6138
  return i18nString(SplitLeft);
6035
6139
  };
6036
- const splitRight$1 = () => {
6140
+ const splitRight = () => {
6037
6141
  return i18nString(SplitRight);
6038
6142
  };
6039
6143
  const splitEditorGroup = () => {
@@ -6149,25 +6253,25 @@ const getMenuEntries$2 = (state, groupId) => {
6149
6253
  command: 'Main.splitUp',
6150
6254
  flags: None$1,
6151
6255
  id: 'splitUp',
6152
- label: splitUp$1()
6256
+ label: splitUp()
6153
6257
  }, {
6154
6258
  args: groupArgs,
6155
6259
  command: 'Main.splitDown',
6156
6260
  flags: None$1,
6157
6261
  id: 'splitDown',
6158
- label: splitDown$1()
6262
+ label: splitDown()
6159
6263
  }, {
6160
6264
  args: groupArgs,
6161
6265
  command: 'Main.splitLeft',
6162
6266
  flags: None$1,
6163
6267
  id: 'splitLeft',
6164
- label: splitLeft$1()
6268
+ label: splitLeft()
6165
6269
  }, {
6166
6270
  args: groupArgs,
6167
6271
  command: 'Main.splitRight',
6168
6272
  flags: None$1,
6169
6273
  id: 'splitRight',
6170
- label: splitRight$1()
6274
+ label: splitRight()
6171
6275
  }, ...getNewWindowMenuEntries(state)];
6172
6276
  if (!hasTargetGroup(groupId)) {
6173
6277
  return entries;
@@ -6281,7 +6385,7 @@ const getMenuEntries$1 = state => {
6281
6385
  command: 'Main.splitRight',
6282
6386
  flags: None$1,
6283
6387
  id: 'splitRight',
6284
- label: splitRight$1()
6388
+ label: splitRight()
6285
6389
  }, {
6286
6390
  command: '',
6287
6391
  flags: None$1,
@@ -7450,7 +7554,7 @@ const renderEventListeners = () => {
7450
7554
  params: ['handleDragLeave']
7451
7555
  }, {
7452
7556
  name: HandleDrop,
7453
- params: ['handleDrop', DataTransferFiles2, DataTransferFiles],
7557
+ params: ['handleDrop', DataTransferFiles2],
7454
7558
  preventDefault: true
7455
7559
  }];
7456
7560
  };
@@ -7878,152 +7982,6 @@ const setEditorLayoutTwoColumnsBottom = state => {
7878
7982
  }]);
7879
7983
  };
7880
7984
 
7881
- const splitDown = (state, groupId) => {
7882
- const {
7883
- layout
7884
- } = state;
7885
- const {
7886
- activeGroupId,
7887
- direction,
7888
- groups
7889
- } = layout;
7890
-
7891
- // If there are no groups, create an initial empty group first
7892
- if (groups.length === 0) {
7893
- const initialGroupId = create$2();
7894
- const initialGroup = {
7895
- activeTabId: -1,
7896
- direction,
7897
- focused: true,
7898
- id: initialGroupId,
7899
- isEmpty: true,
7900
- size: 100,
7901
- tabs: []
7902
- };
7903
- const stateWithInitialGroup = {
7904
- ...state,
7905
- layout: {
7906
- ...layout,
7907
- activeGroupId: initialGroupId,
7908
- groups: [initialGroup]
7909
- }
7910
- };
7911
- return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, 'down');
7912
- }
7913
- const resolvedGroupId = groupId ?? activeGroupId;
7914
- if (!resolvedGroupId) {
7915
- return state;
7916
- }
7917
- return splitEditorGroup$1(state, resolvedGroupId, 'down');
7918
- };
7919
-
7920
- const splitLeft = (state, groupId) => {
7921
- const {
7922
- layout
7923
- } = state;
7924
- const {
7925
- activeGroupId,
7926
- direction,
7927
- groups
7928
- } = layout;
7929
- if (groups.length === 0) {
7930
- const initialGroupId = create$2();
7931
- const initialGroup = {
7932
- activeTabId: -1,
7933
- direction,
7934
- focused: true,
7935
- id: initialGroupId,
7936
- isEmpty: true,
7937
- size: 100,
7938
- tabs: []
7939
- };
7940
- const stateWithInitialGroup = {
7941
- ...state,
7942
- layout: {
7943
- ...layout,
7944
- activeGroupId: initialGroupId,
7945
- groups: [initialGroup]
7946
- }
7947
- };
7948
- return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, Left$1);
7949
- }
7950
- const targetGroupId = groupId ?? (activeGroupId === -1 ? groups[0]?.id : activeGroupId) ?? 0;
7951
- return splitEditorGroup$1(state, targetGroupId, Left$1);
7952
- };
7953
-
7954
- const splitRight = (state, groupId) => {
7955
- const {
7956
- layout
7957
- } = state;
7958
- const {
7959
- activeGroupId,
7960
- direction,
7961
- groups
7962
- } = layout;
7963
-
7964
- // If there are no groups, create an initial empty group first
7965
- if (groups.length === 0) {
7966
- const initialGroupId = create$2();
7967
- const initialGroup = {
7968
- activeTabId: -1,
7969
- direction,
7970
- focused: true,
7971
- id: initialGroupId,
7972
- isEmpty: true,
7973
- size: 100,
7974
- tabs: []
7975
- };
7976
- const stateWithInitialGroup = {
7977
- ...state,
7978
- layout: {
7979
- ...layout,
7980
- activeGroupId: initialGroupId,
7981
- groups: [initialGroup]
7982
- }
7983
- };
7984
- return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, Right$1);
7985
- }
7986
- const targetGroupId = groupId ?? (activeGroupId === -1 ? groups[0]?.id : activeGroupId) ?? 0;
7987
- return splitEditorGroup$1(state, targetGroupId, Right$1);
7988
- };
7989
-
7990
- const splitUp = (state, groupId) => {
7991
- const {
7992
- layout
7993
- } = state;
7994
- const {
7995
- activeGroupId,
7996
- direction,
7997
- groups
7998
- } = layout;
7999
- if (groups.length === 0) {
8000
- const initialGroupId = create$2();
8001
- const initialGroup = {
8002
- activeTabId: -1,
8003
- direction,
8004
- focused: true,
8005
- id: initialGroupId,
8006
- isEmpty: true,
8007
- size: 100,
8008
- tabs: []
8009
- };
8010
- const stateWithInitialGroup = {
8011
- ...state,
8012
- layout: {
8013
- ...layout,
8014
- activeGroupId: initialGroupId,
8015
- groups: [initialGroup]
8016
- }
8017
- };
8018
- return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, 'up');
8019
- }
8020
- const resolvedGroupId = groupId ?? activeGroupId;
8021
- if (!resolvedGroupId) {
8022
- return state;
8023
- }
8024
- return splitEditorGroup$1(state, resolvedGroupId, 'up');
8025
- };
8026
-
8027
7985
  const pendingLoads = new Map();
8028
7986
  const loadContent = wrapSerialCommand(loadContent$1);
8029
7987
  const loadContentTracked = async (uid, ...args) => {
@@ -8075,7 +8033,7 @@ const commandMap = {
8075
8033
  'Main.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
8076
8034
  'Main.save': wrapSerialCommand(save),
8077
8035
  'Main.saveState': wrapGetter(saveState),
8078
- 'Main.splitRight': wrapSerialCommand(splitRight),
8036
+ 'Main.splitRight': wrapSerialCommand(splitRight$1),
8079
8037
  'MainArea.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
8080
8038
  'MainArea.closeAll': wrapSerialCommand(closeAll$1),
8081
8039
  'MainArea.closeAllEditors': wrapSerialCommand(closeAll$1),
@@ -8149,10 +8107,10 @@ const commandMap = {
8149
8107
  'MainArea.setEditorLayoutTwoColumnsBottom': wrapSerialCommand(setEditorLayoutTwoColumnsBottom),
8150
8108
  'MainArea.setEditorLayoutTwoRows': wrapSerialCommand(setEditorLayoutTwoRows),
8151
8109
  'MainArea.setEditorLayoutTwoRowsRight': wrapSerialCommand(setEditorLayoutTwoRowsRight),
8152
- 'MainArea.splitDown': wrapSerialCommand(splitDown),
8153
- 'MainArea.splitLeft': wrapSerialCommand(splitLeft),
8154
- 'MainArea.splitRight': wrapSerialCommand(splitRight),
8155
- 'MainArea.splitUp': wrapSerialCommand(splitUp),
8110
+ 'MainArea.splitDown': wrapSerialCommand(splitDown$1),
8111
+ 'MainArea.splitLeft': wrapSerialCommand(splitLeft$1),
8112
+ 'MainArea.splitRight': wrapSerialCommand(splitRight$1),
8113
+ 'MainArea.splitUp': wrapSerialCommand(splitUp$1),
8156
8114
  'MainArea.terminate': terminate
8157
8115
  };
8158
8116
 
@@ -8162,11 +8120,25 @@ const sendMessagePortToClipBoardWorker = async port => {
8162
8120
  };
8163
8121
 
8164
8122
  const initializeClipBoardWorker = async () => {
8165
- const rpc = await create$7({
8123
+ const rpc = await create$9({
8166
8124
  commandMap: {},
8167
8125
  send: sendMessagePortToClipBoardWorker
8168
8126
  });
8169
- set$4(rpc);
8127
+ set$5(rpc);
8128
+ };
8129
+
8130
+ const send$1 = async port => {
8131
+ await sendMessagePortToDragAndDropWorker(port);
8132
+ };
8133
+ const createDragAndDropWorkerRpc = async () => {
8134
+ return create$6({
8135
+ commandMap: {},
8136
+ send: send$1
8137
+ });
8138
+ };
8139
+
8140
+ const initializeDragAndDropWorker = async () => {
8141
+ set$3(await createDragAndDropWorkerRpc());
8170
8142
  };
8171
8143
 
8172
8144
  const send = port => {
@@ -8211,12 +8183,12 @@ const initializeRendererWorker = async () => {
8211
8183
 
8212
8184
  const listen = async () => {
8213
8185
  registerCommands(commandMap);
8214
- await Promise.all([initializeRendererWorker(), initializeIconThemeWorker(), initializeClipBoardWorker()]);
8186
+ await Promise.all([initializeRendererWorker(), initializeIconThemeWorker(), initializeClipBoardWorker(), initializeDragAndDropWorker()]);
8215
8187
  const dialogRpc = await create$6({
8216
8188
  commandMap: {},
8217
8189
  send: sendMessagePortToDialogWorker
8218
8190
  });
8219
- set$3(dialogRpc);
8191
+ set$4(dialogRpc);
8220
8192
  };
8221
8193
 
8222
8194
  const main$1 = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.37.5",
3
+ "version": "9.37.6",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",