@lvce-editor/editor-worker 19.67.8 → 19.68.1

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.
@@ -1303,7 +1303,7 @@ const Editor$2 = 3;
1303
1303
  const SourceControl = 22;
1304
1304
 
1305
1305
  const Separator = 1;
1306
- const None = 0;
1306
+ const None$1 = 0;
1307
1307
 
1308
1308
  const Electron = 2;
1309
1309
 
@@ -4619,6 +4619,45 @@ const invoke$8 = async (applicationId, method, ...args) => {
4619
4619
  return applicationId === undefined ? invoke$g(method, ...args) : invoke$g('Extensions.invokeForApplication', applicationId, method, ...args);
4620
4620
  };
4621
4621
 
4622
+ const getTextDocument$3 = editor => ({
4623
+ documentId: editor.id || editor.uid,
4624
+ languageId: editor.languageId,
4625
+ text: getText$1(editor),
4626
+ uri: editor.uri
4627
+ });
4628
+ const execute = async ({
4629
+ args,
4630
+ editor,
4631
+ kind,
4632
+ method,
4633
+ noProviderFoundResult = undefined
4634
+ }) => {
4635
+ if (editor.largeFile) {
4636
+ return noProviderFoundResult;
4637
+ }
4638
+ const textDocument = getTextDocument$3(editor);
4639
+ const result = await invoke$8(editor.applicationId, 'Extensions.executeLanguageProvider', kind, method, textDocument, ...args);
4640
+ if (!result.found) {
4641
+ return noProviderFoundResult;
4642
+ }
4643
+ return result.result;
4644
+ };
4645
+
4646
+ const getDocumentSymbols = async editor => {
4647
+ try {
4648
+ const result = await execute({
4649
+ args: [],
4650
+ editor,
4651
+ kind: 'document symbol',
4652
+ method: 'provideDocumentSymbols',
4653
+ noProviderFoundResult: []
4654
+ });
4655
+ return Array.isArray(result) ? result : [];
4656
+ } catch {
4657
+ return [];
4658
+ }
4659
+ };
4660
+
4622
4661
  const validTypes = new Set(['added', 'deleted', 'modified']);
4623
4662
  const isProviderDecoration$1 = value => {
4624
4663
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
@@ -5127,6 +5166,12 @@ const updateDerivedState = async (oldState, newState) => {
5127
5166
  incrementalEdits: emptyIncrementalEdits
5128
5167
  };
5129
5168
  let finalState = nextState;
5169
+ if (nextState.breadcrumbsEnabled && oldState.lines !== nextState.lines && oldState.documentSymbols === nextState.documentSymbols) {
5170
+ finalState = {
5171
+ ...finalState,
5172
+ documentSymbols: await getDocumentSymbols(nextState)
5173
+ };
5174
+ }
5130
5175
  if (shouldUpdateVisibleTextData(oldState, nextState)) {
5131
5176
  const syncIncremental = getEnabled();
5132
5177
  const {
@@ -5134,7 +5179,7 @@ const updateDerivedState = async (oldState, newState) => {
5134
5179
  textInfos
5135
5180
  } = await getVisible$1(nextState, syncIncremental);
5136
5181
  finalState = {
5137
- ...nextState,
5182
+ ...finalState,
5138
5183
  differences,
5139
5184
  textInfos
5140
5185
  };
@@ -5865,7 +5910,7 @@ const isEqual$3 = (oldState, newState) => {
5865
5910
  };
5866
5911
 
5867
5912
  const isEqual$2 = (oldState, newState) => {
5868
- return oldState.breadcrumbsEnabled === newState.breadcrumbsEnabled && oldState.breakPoints === newState.breakPoints && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.documentSymbols === newState.documentSymbols && oldState.endOfLineDecorations === newState.endOfLineDecorations && oldState.focused === newState.focused && oldState.gutterDecorations === newState.gutterDecorations && oldState.highlightActiveLineNumber === newState.highlightActiveLineNumber && oldState.highlightedLine === newState.highlightedLine && oldState.problemsHighlightedRow === newState.problemsHighlightedRow && oldState.lineNumbers === newState.lineNumbers && oldState.loadError === newState.loadError && oldState.textInfos === newState.textInfos && oldState.visibleViewLineIndices === newState.visibleViewLineIndices && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selectionInfos === newState.selectionInfos && oldState.selections === newState.selections && oldState.workspaceUri === newState.workspaceUri;
5913
+ return oldState.breadcrumbFileIcon === newState.breadcrumbFileIcon && oldState.breadcrumbsEnabled === newState.breadcrumbsEnabled && oldState.breakPoints === newState.breakPoints && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.documentSymbols === newState.documentSymbols && oldState.endOfLineDecorations === newState.endOfLineDecorations && oldState.focused === newState.focused && oldState.gutterDecorations === newState.gutterDecorations && oldState.highlightActiveLineNumber === newState.highlightActiveLineNumber && oldState.highlightedLine === newState.highlightedLine && oldState.problemsHighlightedRow === newState.problemsHighlightedRow && oldState.lineNumbers === newState.lineNumbers && oldState.loadError === newState.loadError && oldState.textInfos === newState.textInfos && oldState.visibleViewLineIndices === newState.visibleViewLineIndices && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selectionInfos === newState.selectionInfos && oldState.selections === newState.selections && oldState.workspaceUri === newState.workspaceUri;
5869
5914
  };
5870
5915
 
5871
5916
  const isEqual$1 = (oldState, newState) => {
@@ -7245,30 +7290,6 @@ const handleBlur$1 = async editor => {
7245
7290
  return save(newEditor);
7246
7291
  };
7247
7292
 
7248
- const getTextDocument$3 = editor => ({
7249
- documentId: editor.id || editor.uid,
7250
- languageId: editor.languageId,
7251
- text: getText$1(editor),
7252
- uri: editor.uri
7253
- });
7254
- const execute = async ({
7255
- args,
7256
- editor,
7257
- kind,
7258
- method,
7259
- noProviderFoundResult = undefined
7260
- }) => {
7261
- if (editor.largeFile) {
7262
- return noProviderFoundResult;
7263
- }
7264
- const textDocument = getTextDocument$3(editor);
7265
- const result = await invoke$8(editor.applicationId, 'Extensions.executeLanguageProvider', kind, method, textDocument, ...args);
7266
- if (!result.found) {
7267
- return noProviderFoundResult;
7268
- }
7269
- return result.result;
7270
- };
7271
-
7272
7293
  const replaceRange = (editor, ranges, replacement, origin) => {
7273
7294
  const changes = [];
7274
7295
  const columnDeltas = new Map();
@@ -11686,9 +11707,105 @@ const pasteText = (editor, text) => {
11686
11707
  return scheduleDocumentAndCursorsSelections(editor, changes);
11687
11708
  };
11688
11709
 
11689
- const paste = async editor => {
11690
- const text = await readClipBoardText();
11710
+ const getImageExtension = type => {
11711
+ const subtype = type.slice('image/'.length).toLowerCase().split('+', 1)[0];
11712
+ if (subtype === 'jpeg') {
11713
+ return 'jpg';
11714
+ }
11715
+ return /^[a-z0-9]+$/.test(subtype) ? subtype : 'png';
11716
+ };
11717
+ const getImageUri = (documentUri, fileName) => {
11718
+ if (URL.canParse(documentUri)) {
11719
+ const url = new URL(documentUri);
11720
+ url.pathname = `${url.pathname.slice(0, url.pathname.lastIndexOf('/') + 1)}${fileName}`;
11721
+ url.search = '';
11722
+ url.hash = '';
11723
+ return url.href;
11724
+ }
11725
+ const slashIndex = documentUri.lastIndexOf('/');
11726
+ if (slashIndex === -1) {
11727
+ throw new Error('Save the Markdown document before pasting an image.');
11728
+ }
11729
+ return `${documentUri.slice(0, slashIndex + 1)}${fileName}`;
11730
+ };
11731
+ const toBinaryString = async blob => {
11732
+ const bytes = new Uint8Array(await blob.arrayBuffer());
11733
+ const chunks = [];
11734
+ for (let index = 0; index < bytes.length; index += 8192) {
11735
+ chunks.push(String.fromCodePoint(...bytes.subarray(index, index + 8192)));
11736
+ }
11737
+ return chunks.join('');
11738
+ };
11739
+ const isFileExistsError = error => {
11740
+ if (!(error instanceof Error)) {
11741
+ return false;
11742
+ }
11743
+ const cause = 'cause' in error ? error.cause : undefined;
11744
+ return /already exists|EEXIST/i.test(error.message) || cause !== undefined && isFileExistsError(cause);
11745
+ };
11746
+ const writeClipboardImage = async (editor, blob) => {
11747
+ const extension = getImageExtension(blob.type);
11748
+ for (let index = 0; index < 1000; index++) {
11749
+ const fileName = index === 0 ? `image.${extension}` : `image-${index}.${extension}`;
11750
+ const uri = getImageUri(editor.uri, fileName);
11751
+ try {
11752
+ await invoke$9(editor.applicationId, 'FileSystem.createFile', uri);
11753
+ } catch (error) {
11754
+ if (isFileExistsError(error)) {
11755
+ continue;
11756
+ }
11757
+ throw error;
11758
+ }
11759
+ try {
11760
+ await invoke$9(editor.applicationId, 'FileSystem.writeFile', uri, await toBinaryString(blob), 'binary');
11761
+ return {
11762
+ fileName,
11763
+ uri
11764
+ };
11765
+ } catch (error) {
11766
+ try {
11767
+ await invoke$9(editor.applicationId, 'FileSystem.remove', uri);
11768
+ } catch {}
11769
+ throw error;
11770
+ }
11771
+ }
11772
+ throw new Error('Could not find an unused filename for the pasted image.');
11773
+ };
11774
+ const paste = async (editor, pastedText) => {
11775
+ let imageReadError;
11776
+ if (editor.languageId === 'markdown') {
11777
+ let image;
11778
+ try {
11779
+ image = await invoke$d('ClipBoard.readImage');
11780
+ } catch (error) {
11781
+ imageReadError = error;
11782
+ }
11783
+ if (image instanceof Blob) {
11784
+ let savedImage;
11785
+ try {
11786
+ savedImage = await writeClipboardImage(editor, image);
11787
+ } catch (error) {
11788
+ throw new Error('Failed to save the clipboard image beside the Markdown document.', {
11789
+ cause: error
11790
+ });
11791
+ }
11792
+ const currentEditor = get$8(editor.uid)?.newState;
11793
+ if (!currentEditor || currentEditor.uri !== editor.uri || currentEditor.languageId !== 'markdown') {
11794
+ try {
11795
+ await invoke$9(editor.applicationId, 'FileSystem.remove', savedImage.uri);
11796
+ } catch {}
11797
+ throw new Error('The Markdown document changed while saving the clipboard image. Paste the image again.');
11798
+ }
11799
+ return pasteText(currentEditor, `![image](${savedImage.fileName})`);
11800
+ }
11801
+ }
11802
+ const text = pastedText ?? (await readClipBoardText());
11691
11803
  string(text);
11804
+ if (imageReadError && text.length === 0) {
11805
+ throw new Error('Unable to read an image from the clipboard. Check clipboard permissions and try again.', {
11806
+ cause: imageReadError
11807
+ });
11808
+ }
11692
11809
  return pasteText(editor, text);
11693
11810
  };
11694
11811
 
@@ -13581,6 +13698,7 @@ const EditorLineDecoration = 'EditorLineDecoration';
13581
13698
  const EditorRow = 'EditorRow';
13582
13699
  const EditorRowHighlighted = 'EditorRowHighlighted';
13583
13700
  const EditorSelection = 'EditorSelection';
13701
+ const FileIcon = 'FileIcon';
13584
13702
  const HoverDisplayString = 'HoverDisplayString';
13585
13703
  const HoverDocumentation = 'HoverDocumentation';
13586
13704
  const HoverEditorRow = 'HoverEditorRow';
@@ -13625,6 +13743,7 @@ const Button$1 = 1;
13625
13743
  const Div = 4;
13626
13744
  const Input = 6;
13627
13745
  const Span = 8;
13746
+ const Img = 17;
13628
13747
  const Nav = 40;
13629
13748
  const TextArea = 62;
13630
13749
 
@@ -14753,54 +14872,54 @@ const menuEntrySeparator = {
14753
14872
  const getMenuEntries = () => {
14754
14873
  return [{
14755
14874
  command: 'Editor.goToDefinition',
14756
- flags: None,
14875
+ flags: None$1,
14757
14876
  id: 'go-to-definition',
14758
14877
  label: goToDefinition$1()
14759
14878
  }, {
14760
14879
  command: /* Editor.goToTypeDefinition */'Editor.goToTypeDefinition',
14761
- flags: None,
14880
+ flags: None$1,
14762
14881
  id: 'go-to-type-definition',
14763
14882
  label: goToTypeDefinition$1()
14764
14883
  }, menuEntrySeparator, {
14765
14884
  args: [/* id */'References', /* focus */true],
14766
14885
  command: /* ViewletSideBar.show */'SideBar.show',
14767
- flags: None,
14886
+ flags: None$1,
14768
14887
  id: 'find-all-references',
14769
14888
  label: findAllReferences()
14770
14889
  }, {
14771
14890
  args: [/* id */'Implementations', /* focus */true],
14772
14891
  command: /* ViewletSideBar.show */'SideBar.show',
14773
- flags: None,
14892
+ flags: None$1,
14774
14893
  id: 'find-all-implementations',
14775
14894
  label: findAllImplementations()
14776
14895
  }, menuEntrySeparator, {
14777
14896
  command: 'Editor.format',
14778
- flags: None,
14897
+ flags: None$1,
14779
14898
  id: 'format',
14780
14899
  label: formatDocument()
14781
14900
  }, {
14782
14901
  command: 'Editor.showSourceActions2',
14783
- flags: None,
14902
+ flags: None$1,
14784
14903
  id: SourceControl,
14785
14904
  label: sourceAction()
14786
14905
  }, menuEntrySeparator, {
14787
14906
  command: /* Editor.cut */'Editor.cut',
14788
- flags: None,
14907
+ flags: None$1,
14789
14908
  id: 'cut',
14790
14909
  label: cut()
14791
14910
  }, {
14792
14911
  command: /* Editor.copy */'Editor.copy',
14793
- flags: None,
14912
+ flags: None$1,
14794
14913
  id: 'copy',
14795
14914
  label: copy()
14796
14915
  }, {
14797
14916
  command: /* Editor.paste */'Editor.paste',
14798
- flags: None,
14917
+ flags: None$1,
14799
14918
  id: 'paste',
14800
14919
  label: paste$1()
14801
14920
  }, menuEntrySeparator, {
14802
14921
  command: 'QuickPick.showEverything',
14803
- flags: None,
14922
+ flags: None$1,
14804
14923
  id: 'commandPalette',
14805
14924
  label: commandPalette()
14806
14925
  }];
@@ -14976,18 +15095,14 @@ const handleMessagePort = async (port, rpcId) => {
14976
15095
  }
14977
15096
  };
14978
15097
 
14979
- const getDocumentSymbols = async editor => {
15098
+ const getBreadcrumbFileIcon = async (uri, applicationId) => {
14980
15099
  try {
14981
- const result = await execute({
14982
- args: [],
14983
- editor,
14984
- kind: 'document symbol',
14985
- method: 'provideDocumentSymbols',
14986
- noProviderFoundResult: []
15100
+ const icon = await invoke$9(applicationId, 'IconTheme.getFileIcon', {
15101
+ name: decodeURIComponent(uri.split('/').at(-1) || '')
14987
15102
  });
14988
- return Array.isArray(result) ? result : [];
15103
+ return typeof icon === 'string' ? icon : '';
14989
15104
  } catch {
14990
- return [];
15105
+ return '';
14991
15106
  }
14992
15107
  };
14993
15108
 
@@ -15162,14 +15277,20 @@ const handleSettingsChanged = async state => {
15162
15277
  }
15163
15278
  let documentSymbols = state.documentSymbols || [];
15164
15279
  let workspaceUri = state.workspaceUri || '';
15280
+ let breadcrumbFileIcon = state.breadcrumbFileIcon || '';
15165
15281
  if (!breadcrumbsEnabled) {
15166
15282
  documentSymbols = [];
15167
15283
  workspaceUri = '';
15284
+ breadcrumbFileIcon = '';
15168
15285
  } else if (!state.breadcrumbsEnabled) {
15169
15286
  [documentSymbols, workspaceUri] = await Promise.all([getDocumentSymbols(editorWithUpdatedSettings), getWorkspaceUri$1(state.applicationId)]);
15170
15287
  }
15288
+ if (breadcrumbsEnabled) {
15289
+ breadcrumbFileIcon = await getBreadcrumbFileIcon(state.uri, state.applicationId);
15290
+ }
15171
15291
  const resizedEditor = resize$2({
15172
15292
  ...editorWithUpdatedSettings,
15293
+ breadcrumbFileIcon,
15173
15294
  documentSymbols,
15174
15295
  workspaceUri
15175
15296
  }, {}, charWidth);
@@ -15593,11 +15714,14 @@ const loadContent = async (state, savedState, largeFile = false) => {
15593
15714
  };
15594
15715
  let documentSymbols = state.documentSymbols || [];
15595
15716
  let workspaceUri = state.workspaceUri || '';
15717
+ let breadcrumbFileIcon = state.breadcrumbFileIcon || '';
15596
15718
  if (effectiveEditor.breadcrumbsEnabled) {
15719
+ breadcrumbFileIcon = await getBreadcrumbFileIcon(uri, state.applicationId);
15597
15720
  [documentSymbols, workspaceUri] = await Promise.all([getDocumentSymbols(newEditor3WithLinks), getWorkspaceUri(state.applicationId)]);
15598
15721
  }
15599
15722
  const newEditor3WithBreadcrumbs = {
15600
15723
  ...newEditor3WithLinks,
15724
+ breadcrumbFileIcon,
15601
15725
  documentSymbols,
15602
15726
  workspaceUri
15603
15727
  };
@@ -15893,6 +16017,7 @@ const True = 'true';
15893
16017
 
15894
16018
  const Button = 'button';
15895
16019
  const Code = 'code';
16020
+ const None = 'none';
15896
16021
  const TextBox = 'textbox';
15897
16022
 
15898
16023
  const combineWhitespaceTokens = tokens => {
@@ -15961,6 +16086,24 @@ const getEditorBreadcrumbs = state => {
15961
16086
  return [...getFileBreadcrumbs(uri, workspaceUri || ''), ...getSymbolBreadcrumbs(documentSymbols || [], offset)];
15962
16087
  };
15963
16088
 
16089
+ const getFileIconVirtualDom = icon => {
16090
+ return {
16091
+ childCount: 0,
16092
+ className: FileIcon,
16093
+ role: None,
16094
+ src: icon,
16095
+ type: Img
16096
+ };
16097
+ };
16098
+
16099
+ const symbolIcons = {
16100
+ 15: 'String',
16101
+ 16: 'Number',
16102
+ 17: 'Boolean',
16103
+ 18: 'Array',
16104
+ 19: 'Object',
16105
+ 21: 'Null'
16106
+ };
15964
16107
  const separator = {
15965
16108
  ariaHidden: True,
15966
16109
  childCount: 0,
@@ -15968,6 +16111,9 @@ const separator = {
15968
16111
  type: Span
15969
16112
  };
15970
16113
  const getEditorBreadcrumbsVirtualDom = state => {
16114
+ const {
16115
+ breadcrumbFileIcon
16116
+ } = state;
15971
16117
  const breadcrumbs = getEditorBreadcrumbs(state);
15972
16118
  const children = [];
15973
16119
  for (let index = 0; index < breadcrumbs.length; index++) {
@@ -15975,19 +16121,29 @@ const getEditorBreadcrumbsVirtualDom = state => {
15975
16121
  if (index > 0) {
15976
16122
  children.push(separator);
15977
16123
  }
16124
+ const isFile = breadcrumb.kind === 'file' && breadcrumbs[index + 1]?.kind !== 'file';
16125
+ const icon = breadcrumb.kind === 'symbol' ? {
16126
+ ariaHidden: True,
16127
+ childCount: 0,
16128
+ className: mergeClassNames('EditorBreadcrumbIcon', 'MaskIcon', `MaskIconSymbol${symbolIcons[String(breadcrumb.symbolKind)] || 'Default'}`),
16129
+ type: Span
16130
+ } : isFile && breadcrumbFileIcon ? {
16131
+ ...getFileIconVirtualDom(breadcrumbFileIcon),
16132
+ ariaHidden: True
16133
+ } : undefined;
15978
16134
  children.push({
15979
- childCount: 1,
16135
+ childCount: icon ? 2 : 1,
15980
16136
  className: mergeClassNames('EditorBreadcrumb', breadcrumb.kind === 'symbol' ? 'EditorBreadcrumbSymbol' : 'EditorBreadcrumbFile'),
15981
16137
  'data-kind': breadcrumb.kind,
15982
16138
  ...(breadcrumb.symbolKind !== undefined && {
15983
16139
  'data-symbolKind': breadcrumb.symbolKind
15984
16140
  }),
15985
16141
  type: Span
15986
- }, text(breadcrumb.label));
16142
+ }, ...(icon ? [icon] : []), text(breadcrumb.label));
15987
16143
  }
15988
16144
  return [{
15989
16145
  ariaLabel: 'Breadcrumbs',
15990
- childCount: children.length,
16146
+ childCount: breadcrumbs.length > 0 ? breadcrumbs.length * 2 - 1 : 0,
15991
16147
  className: 'EditorBreadcrumbs',
15992
16148
  type: Nav
15993
16149
  }, ...children];
@@ -16510,6 +16666,7 @@ const getMinimapVirtualDom = (minimapEnabled, minimapLines, minLineY, breadcrumb
16510
16666
  };
16511
16667
  const getEditorVirtualDom = ({
16512
16668
  bracketMatchInfos = [],
16669
+ breadcrumbFileIcon = '',
16513
16670
  breadcrumbsEnabled = false,
16514
16671
  breakPoints = [],
16515
16672
  combineWhitespaceTokens: combineWhitespaceTokens$1 = false,
@@ -16561,6 +16718,7 @@ const getEditorVirtualDom = ({
16561
16718
  const gutterDom = showGutter ? getEditorGutterVirtualDom(visibleGutterInfos, activeLineNumber, breadcrumbsEnabled) : [];
16562
16719
  const minimapDom = getMinimapVirtualDom(minimapEnabled, minimapLines, minLineY, breadcrumbsEnabled);
16563
16720
  const breadcrumbsDom = breadcrumbsEnabled ? getEditorBreadcrumbsVirtualDom({
16721
+ breadcrumbFileIcon,
16564
16722
  breadcrumbsEnabled,
16565
16723
  documentSymbols,
16566
16724
  lines,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.67.8",
3
+ "version": "19.68.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"