@lvce-editor/editor-worker 19.46.0 → 19.47.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.
@@ -1151,7 +1151,7 @@ const createMockRpc = ({
1151
1151
  };
1152
1152
 
1153
1153
  const rpcs = Object.create(null);
1154
- const set$g = (id, rpc) => {
1154
+ const set$h = (id, rpc) => {
1155
1155
  rpcs[id] = rpc;
1156
1156
  };
1157
1157
  const get$9 = id => {
@@ -1184,7 +1184,7 @@ const create$a = rpcId => {
1184
1184
  const mockRpc = createMockRpc({
1185
1185
  commandMap
1186
1186
  });
1187
- set$g(rpcId, mockRpc);
1187
+ set$h(rpcId, mockRpc);
1188
1188
  // @ts-ignore
1189
1189
  mockRpc[Symbol.dispose] = () => {
1190
1190
  remove$8(rpcId);
@@ -1193,7 +1193,7 @@ const create$a = rpcId => {
1193
1193
  return mockRpc;
1194
1194
  },
1195
1195
  set(rpc) {
1196
- set$g(rpcId, rpc);
1196
+ set$h(rpcId, rpc);
1197
1197
  }
1198
1198
  };
1199
1199
  };
@@ -1439,6 +1439,7 @@ const Electron = 2;
1439
1439
  const CompletionWorker = 301;
1440
1440
  const DebugWorker = 55;
1441
1441
  const DialogWorker = 7014;
1442
+ const DragAndDropWorker = 3404;
1442
1443
  const EditorWorker = 99;
1443
1444
  const ErrorWorker = 3308;
1444
1445
  const ExtensionManagementWorker = 9006;
@@ -1454,10 +1455,15 @@ const SetPatches = 'Viewlet.setPatches';
1454
1455
 
1455
1456
  const FocusEditorText$1 = 12;
1456
1457
 
1458
+ const {
1459
+ invoke: invoke$g,
1460
+ set: set$g
1461
+ } = create$a(DialogWorker);
1462
+
1457
1463
  const {
1458
1464
  invoke: invoke$f,
1459
1465
  set: set$f
1460
- } = create$a(DialogWorker);
1466
+ } = create$a(DragAndDropWorker);
1461
1467
 
1462
1468
  const {
1463
1469
  invoke: invoke$e,
@@ -1485,7 +1491,7 @@ const createLazyRpc = rpcId => {
1485
1491
  throw new Error('Lazy RPC launch was superseded');
1486
1492
  }
1487
1493
  activeRpc = rpc;
1488
- set$g(rpcId, rpc);
1494
+ set$h(rpcId, rpc);
1489
1495
  return rpc;
1490
1496
  };
1491
1497
  const ensureRpc = async () => {
@@ -1570,6 +1576,10 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1570
1576
  number(y);
1571
1577
  await invoke$a('ContextMenu.show2', uid, menuId, x, y, args);
1572
1578
  };
1579
+ const sendMessagePortToDragAndDropWorker = async port => {
1580
+ const command = 'DragAndDrop.handleMessagePort';
1581
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDragAndDropWorker', port, command);
1582
+ };
1573
1583
  const sendMessagePortToOpenerWorker = async (port, rpcId) => {
1574
1584
  const command = 'HandleMessagePort.handleMessagePort';
1575
1585
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
@@ -1940,6 +1950,7 @@ const EditorPasteText = 'editorPasteText';
1940
1950
  const EditorSnippet = 'editorSnippet';
1941
1951
  const EditorType = 'editorType';
1942
1952
  const EditorTypeWithAutoClosing = 'editorTypeWithAutoClosing';
1953
+ const EditorTextDrag = 'editorTextDrag';
1943
1954
  const Format = 'format';
1944
1955
  const IndentLess = 'indentLess';
1945
1956
  const IndentMore = 'indentMore';
@@ -5009,6 +5020,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
5009
5020
  diagnosticsEnabled: false,
5010
5021
  differences: [],
5011
5022
  documentSymbols: [],
5023
+ dragAndDropEnabled: true,
5012
5024
  embeds: [],
5013
5025
  endOfLine: 'lf',
5014
5026
  endOfLineDecorations: [],
@@ -5077,6 +5089,11 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
5077
5089
  selectionInfos: [],
5078
5090
  selections: new Uint32Array(),
5079
5091
  tabSize: 0,
5092
+ textDragDropPosition: {
5093
+ columnIndex: 0,
5094
+ rowIndex: 0
5095
+ },
5096
+ textDragId: 0,
5080
5097
  textInfos: [],
5081
5098
  tokenizerId: 0,
5082
5099
  uid: id,
@@ -5107,6 +5124,7 @@ const emptyEditor = {
5107
5124
  diagnostics: [],
5108
5125
  differences: [],
5109
5126
  documentSymbols: [],
5127
+ dragAndDropEnabled: true,
5110
5128
  embeds: [],
5111
5129
  endOfLine: 'lf',
5112
5130
  endOfLineDecorations: [],
@@ -5143,6 +5161,11 @@ const emptyEditor = {
5143
5161
  },
5144
5162
  selectionInfos: [],
5145
5163
  selections: new Uint32Array(),
5164
+ textDragDropPosition: {
5165
+ columnIndex: 0,
5166
+ rowIndex: 0
5167
+ },
5168
+ textDragId: 0,
5146
5169
  textInfos: [],
5147
5170
  tokenizerId: 0,
5148
5171
  undoStack: [],
@@ -5297,6 +5320,7 @@ const createEditor = async ({
5297
5320
  diagnostics: [],
5298
5321
  diagnosticsEnabled,
5299
5322
  differences: [],
5323
+ dragAndDropEnabled: true,
5300
5324
  endOfLine: getEndOfLine(content),
5301
5325
  endOfLineDecorations: [],
5302
5326
  finalDeltaY: 0,
@@ -5354,6 +5378,11 @@ const createEditor = async ({
5354
5378
  selectionInfos: [],
5355
5379
  selections: new Uint32Array(),
5356
5380
  tabSize,
5381
+ textDragDropPosition: {
5382
+ columnIndex: 0,
5383
+ rowIndex: 0
5384
+ },
5385
+ textDragId: 0,
5357
5386
  textInfos: [],
5358
5387
  tokenizerId: 0,
5359
5388
  uid: id,
@@ -6216,7 +6245,7 @@ const isPermissionDeniedError = error => {
6216
6245
  };
6217
6246
  const showSaveErrorDialog = async error => {
6218
6247
  if (isPermissionDeniedError(error)) {
6219
- await invoke$f('ElectronDialog.showMessageBox', {
6248
+ await invoke$g('ElectronDialog.showMessageBox', {
6220
6249
  buttons: ['OK'],
6221
6250
  defaultId: 0,
6222
6251
  message: "You don't have permission to save changes to this file.",
@@ -6225,7 +6254,7 @@ const showSaveErrorDialog = async error => {
6225
6254
  });
6226
6255
  return;
6227
6256
  }
6228
- await invoke$f('ElectronDialog.showMessageBox', {
6257
+ await invoke$g('ElectronDialog.showMessageBox', {
6229
6258
  buttons: ['OK'],
6230
6259
  defaultId: 0,
6231
6260
  detail: error.message,
@@ -8682,13 +8711,50 @@ const handleSecondaryMouseDown = async (state, x, y) => {
8682
8711
  }
8683
8712
  return handleClickAtPosition(state, 0, position.rowIndex, position.columnIndex);
8684
8713
  };
8685
- const handleMouseDown = async (state, button, altKey, ctrlKey, x, y, detail) => {
8714
+ const startTextDrag = async (state, x, y) => {
8715
+ const position = await at(state, x, y);
8716
+ const selectionIndex = state.primarySelectionIndex || 0;
8717
+ const [startRowIndex, startColumnIndex, endRowIndex, endColumnIndex] = getSelectionPairs(state.selections, selectionIndex);
8718
+ const startOffset = offsetAt(state, startRowIndex, startColumnIndex);
8719
+ const endOffset = offsetAt(state, endRowIndex, endColumnIndex);
8720
+ const pointerOffset = offsetAt(state, position.rowIndex, position.columnIndex);
8721
+ if (startOffset === endOffset || pointerOffset < startOffset || pointerOffset >= endOffset) {
8722
+ return undefined;
8723
+ }
8724
+ try {
8725
+ if (state.textDragId) {
8726
+ await invoke$f('DragAndDrop.discardTextDrag', state.textDragId);
8727
+ }
8728
+ const text = getText$1(state).slice(startOffset, endOffset);
8729
+ const textDragId = await invoke$f('DragAndDrop.createTextDrag', {
8730
+ endOffset,
8731
+ sourceUri: state.uri,
8732
+ startOffset,
8733
+ text
8734
+ });
8735
+ return {
8736
+ ...state,
8737
+ isSelecting: false,
8738
+ textDragDropPosition: position,
8739
+ textDragId
8740
+ };
8741
+ } catch {
8742
+ return undefined;
8743
+ }
8744
+ };
8745
+ const handleMouseDown = async (state, button, altKey, ctrlKey, x, y, detail, shiftKey = false) => {
8686
8746
  if (button === SecondaryButton) {
8687
8747
  return handleSecondaryMouseDown(state, x, y);
8688
8748
  }
8689
8749
  if (button !== PrimaryButton) {
8690
8750
  return state;
8691
8751
  }
8752
+ if (shiftKey && state.dragAndDropEnabled && detail === Single) {
8753
+ const dragState = await startTextDrag(state, x, y);
8754
+ if (dragState) {
8755
+ return dragState;
8756
+ }
8757
+ }
8692
8758
  const modifier = getModifier(altKey, ctrlKey);
8693
8759
  let newState;
8694
8760
  switch (detail) {
@@ -9220,7 +9286,14 @@ const editorHandleNativeSelectionChange = (editor, range) => {
9220
9286
  };
9221
9287
 
9222
9288
  // @ts-ignore
9223
- const handlePointerCaptureLost = editor => {
9289
+ const handlePointerCaptureLost = async editor => {
9290
+ if (editor.textDragId) {
9291
+ try {
9292
+ await invoke$f('DragAndDrop.discardTextDrag', editor.textDragId);
9293
+ } catch {
9294
+ // The pointer state still needs to be reset if the worker is unavailable.
9295
+ }
9296
+ }
9224
9297
  return {
9225
9298
  ...editor,
9226
9299
  hasListener: false,
@@ -9228,7 +9301,12 @@ const handlePointerCaptureLost = editor => {
9228
9301
  selectionAutoMovePosition: {
9229
9302
  columnIndex: 0,
9230
9303
  rowIndex: 0
9231
- }
9304
+ },
9305
+ textDragDropPosition: {
9306
+ columnIndex: 0,
9307
+ rowIndex: 0
9308
+ },
9309
+ textDragId: 0
9232
9310
  };
9233
9311
  };
9234
9312
 
@@ -9425,6 +9503,13 @@ const moveSelectionPx = async (editor, x, y) => {
9425
9503
  };
9426
9504
 
9427
9505
  const handlePointerMove = async (editor, x, y, altKey) => {
9506
+ if (editor.textDragId) {
9507
+ const textDragDropPosition = await at(editor, x, y);
9508
+ return {
9509
+ ...editor,
9510
+ textDragDropPosition
9511
+ };
9512
+ }
9428
9513
  if (!editor.isSelecting) {
9429
9514
  return editor;
9430
9515
  }
@@ -9434,16 +9519,84 @@ const handlePointerMove = async (editor, x, y, altKey) => {
9434
9519
  return moveSelectionPx(editor, x, y);
9435
9520
  };
9436
9521
 
9437
- const handlePointerUp = editor => {
9522
+ const getSelection = (lines, startOffset, endOffset) => {
9523
+ const start = positionAt({
9524
+ lines
9525
+ }, startOffset);
9526
+ const end = positionAt({
9527
+ lines
9528
+ }, endOffset);
9529
+ return new Uint32Array([start.rowIndex, start.columnIndex, end.rowIndex, end.columnIndex]);
9530
+ };
9531
+ const getTextDragEdit = (editor, data, target, origin) => {
9532
+ const documentText = getText$1(editor);
9533
+ const targetOffset = offsetAt(editor, target.rowIndex, target.columnIndex);
9534
+ const {
9535
+ endOffset,
9536
+ startOffset,
9537
+ text
9538
+ } = data;
9539
+ if (startOffset < 0 || startOffset >= endOffset || endOffset > documentText.length || documentText.slice(startOffset, endOffset) !== text || targetOffset >= startOffset && targetOffset <= endOffset) {
9540
+ return undefined;
9541
+ }
9542
+ const regionStartOffset = Math.min(startOffset, targetOffset);
9543
+ const regionEndOffset = Math.max(endOffset, targetOffset);
9544
+ const replacement = targetOffset < startOffset ? text + documentText.slice(targetOffset, startOffset) : documentText.slice(endOffset, targetOffset) + text;
9545
+ const newSelectionStartOffset = targetOffset < startOffset ? targetOffset : targetOffset - text.length;
9546
+ const newText = documentText.slice(0, regionStartOffset) + replacement + documentText.slice(regionEndOffset);
9547
+ const newLines = splitLines(newText);
9548
+ const start = positionAt(editor, regionStartOffset);
9549
+ const end = positionAt(editor, regionEndOffset);
9438
9550
  return {
9551
+ change: {
9552
+ deleted: splitLines(documentText.slice(regionStartOffset, regionEndOffset)),
9553
+ end,
9554
+ inserted: splitLines(replacement),
9555
+ origin,
9556
+ start
9557
+ },
9558
+ selections: getSelection(newLines, newSelectionStartOffset, newSelectionStartOffset + text.length)
9559
+ };
9560
+ };
9561
+
9562
+ const moveTextDrag = async (editor, data, target) => {
9563
+ if (data.sourceUri !== editor.uri) {
9564
+ return editor;
9565
+ }
9566
+ const result = getTextDragEdit(editor, data, target, EditorTextDrag);
9567
+ if (!result) {
9568
+ return editor;
9569
+ }
9570
+ return scheduleDocumentAndCursorsSelections(editor, [result.change], result.selections);
9571
+ };
9572
+
9573
+ const handlePointerUp = async editor => {
9574
+ const resetEditor = {
9439
9575
  ...editor,
9440
9576
  hasListener: false,
9441
9577
  isSelecting: false,
9442
9578
  selectionAutoMovePosition: {
9443
9579
  columnIndex: 0,
9444
9580
  rowIndex: 0
9445
- }
9581
+ },
9582
+ textDragDropPosition: {
9583
+ columnIndex: 0,
9584
+ rowIndex: 0
9585
+ },
9586
+ textDragId: 0
9446
9587
  };
9588
+ if (!editor.textDragId) {
9589
+ return resetEditor;
9590
+ }
9591
+ try {
9592
+ const data = await invoke$f('DragAndDrop.takeTextDrag', editor.textDragId);
9593
+ if (!data) {
9594
+ return resetEditor;
9595
+ }
9596
+ return moveTextDrag(resetEditor, data, editor.textDragDropPosition);
9597
+ } catch {
9598
+ return resetEditor;
9599
+ }
9447
9600
  };
9448
9601
 
9449
9602
  // @ts-ignore
@@ -10145,7 +10298,7 @@ const launch = async () => {
10145
10298
  return;
10146
10299
  }
10147
10300
  const rpc = await launchFindWidgetWorker();
10148
- set$g(rpcId, rpc);
10301
+ set$h(rpcId, rpc);
10149
10302
  };
10150
10303
  const invoke$3 = async (method, ...params) => {
10151
10304
  const rpc = get$9(rpcId);
@@ -13505,7 +13658,7 @@ const handleMessagePort = async (port, rpcId) => {
13505
13658
  messagePort: port
13506
13659
  });
13507
13660
  if (rpcId) {
13508
- set$g(rpcId, rpc);
13661
+ set$h(rpcId, rpc);
13509
13662
  }
13510
13663
  };
13511
13664
 
@@ -13539,6 +13692,10 @@ const kFontWeight = 'editor.fontWeight';
13539
13692
  const kHover = 'editor.hover';
13540
13693
  const kMinimapEnabled = 'editor.minimap.enabled';
13541
13694
  const kBreadcrumbsEnabled = 'breadcrumbs.enabled';
13695
+ const kDragAndDropEnabled = 'editor.dragAndDrop';
13696
+ const getDragAndDropEnabled = async () => {
13697
+ return (await get$3(kDragAndDropEnabled)) ?? true;
13698
+ };
13542
13699
  const isAutoClosingBracketsEnabled = async () => {
13543
13700
  return Boolean(await get$3(kAutoClosingBrackets));
13544
13701
  };
@@ -13595,11 +13752,12 @@ const getBreadcrumbsEnabled = async () => {
13595
13752
  };
13596
13753
 
13597
13754
  const getEditorPreferences = async () => {
13598
- const [diagnosticsEnabled$1, fontFamily, fontSize, fontWeight, hoverEnabled, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, breadcrumbsEnabled, insertSpaces] = await Promise.all([diagnosticsEnabled(), getFontFamily(), getFontSize(), getFontWeight(), getHoverEnabled(), isAutoClosingBracketsEnabled(), isAutoClosingQuotesEnabled(), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(), getLineNumbers(), getRowHeight(), getTabSize(), getLetterSpacing(), getCompletionTriggerCharacters(), getMinimapEnabled(), getBreadcrumbsEnabled(), getInsertSpaces()]);
13755
+ const [diagnosticsEnabled$1, fontFamily, fontSize, fontWeight, hoverEnabled, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, breadcrumbsEnabled, insertSpaces, dragAndDropEnabled] = await Promise.all([diagnosticsEnabled(), getFontFamily(), getFontSize(), getFontWeight(), getHoverEnabled(), isAutoClosingBracketsEnabled(), isAutoClosingQuotesEnabled(), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(), getLineNumbers(), getRowHeight(), getTabSize(), getLetterSpacing(), getCompletionTriggerCharacters(), getMinimapEnabled(), getBreadcrumbsEnabled(), getInsertSpaces(), getDragAndDropEnabled()]);
13599
13756
  return {
13600
13757
  breadcrumbsEnabled,
13601
13758
  completionTriggerCharacters,
13602
13759
  diagnosticsEnabled: diagnosticsEnabled$1,
13760
+ dragAndDropEnabled,
13603
13761
  fontFamily,
13604
13762
  fontSize,
13605
13763
  fontWeight,
@@ -13939,6 +14097,7 @@ const loadContent = async (state, savedState) => {
13939
14097
  breadcrumbsEnabled,
13940
14098
  completionTriggerCharacters,
13941
14099
  diagnosticsEnabled,
14100
+ dragAndDropEnabled,
13942
14101
  fontFamily,
13943
14102
  fontSize,
13944
14103
  fontWeight,
@@ -13970,6 +14129,7 @@ const loadContent = async (state, savedState) => {
13970
14129
  charWidth,
13971
14130
  completionTriggerCharacters,
13972
14131
  diagnosticsEnabled,
14132
+ dragAndDropEnabled,
13973
14133
  fontFamily,
13974
14134
  fontSize,
13975
14135
  fontWeight,
@@ -15421,7 +15581,7 @@ const renderEventListeners = () => {
15421
15581
  preventDefault: true
15422
15582
  }, {
15423
15583
  name: HandleMouseDown,
15424
- params: ['handleMouseDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY, 'event.detail']
15584
+ params: ['handleMouseDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY, 'event.detail', 'event.shiftKey']
15425
15585
  }, {
15426
15586
  name: HandlePointerDown,
15427
15587
  params: ['handlePointerDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY, 'event.detail', 'event.currentTarget.parentElement.parentElement.offsetLeft'],
@@ -16089,6 +16249,14 @@ for (const [key, value] of Object.entries(commandMap)) {
16089
16249
  }
16090
16250
  }
16091
16251
 
16252
+ const initializeDragAndDropWorker = async () => {
16253
+ const rpc = await create$d({
16254
+ commandMap: {},
16255
+ send: sendMessagePortToDragAndDropWorker
16256
+ });
16257
+ set$f(rpc);
16258
+ };
16259
+
16092
16260
  const initializeErrorWorker = async () => {
16093
16261
  const rpc = await create$d({
16094
16262
  commandMap: {},
@@ -16150,12 +16318,12 @@ const initializeTextMeasurementWorker = async () => {
16150
16318
 
16151
16319
  const listen = async () => {
16152
16320
  registerCommands(commandMap);
16153
- await Promise.all([initializeRendererWorker(), initializeErrorWorker(), initializeExtensionManagementWorker(), initializeTextMeasurementWorker(), initializeOpenerWorker()]);
16321
+ await Promise.all([initializeRendererWorker(), initializeDragAndDropWorker(), initializeErrorWorker(), initializeExtensionManagementWorker(), initializeTextMeasurementWorker(), initializeOpenerWorker()]);
16154
16322
  const dialogRpc = await create$d({
16155
16323
  commandMap: {},
16156
16324
  send: sendMessagePortToDialogWorker
16157
16325
  });
16158
- set$f(dialogRpc);
16326
+ set$g(dialogRpc);
16159
16327
  };
16160
16328
 
16161
16329
  const CodeGeneratorInput = 'CodeGeneratorInput';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.46.0",
3
+ "version": "19.47.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"