@lvce-editor/editor-worker 18.1.0 → 18.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.
@@ -474,7 +474,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
474
474
  return promise;
475
475
  };
476
476
  const Message$1 = 3;
477
- const create$5$2 = async ({
477
+ const create$5$1 = async ({
478
478
  isMessagePortOpen,
479
479
  messagePort
480
480
  }) => {
@@ -525,11 +525,32 @@ const wrap$5 = messagePort => {
525
525
  };
526
526
  const IpcParentWithMessagePort$1 = {
527
527
  __proto__: null,
528
- create: create$5$2,
528
+ create: create$5$1,
529
529
  signal: signal$1,
530
530
  wrap: wrap$5
531
531
  };
532
532
 
533
+ class CommandNotFoundError extends Error {
534
+ constructor(command) {
535
+ super(`Command not found ${command}`);
536
+ this.name = 'CommandNotFoundError';
537
+ }
538
+ }
539
+ const commands = Object.create(null);
540
+ const register = commandMap => {
541
+ Object.assign(commands, commandMap);
542
+ };
543
+ const getCommand = key => {
544
+ return commands[key];
545
+ };
546
+ const execute$1 = (command, ...args) => {
547
+ const fn = getCommand(command);
548
+ if (!fn) {
549
+ throw new CommandNotFoundError(command);
550
+ }
551
+ return fn(...args);
552
+ };
553
+
533
554
  const Two$1 = '2.0';
534
555
  const callbacks = Object.create(null);
535
556
  const get$8 = id => {
@@ -744,7 +765,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
744
765
  const errorProperty = getErrorProperty(error, prettyError);
745
766
  return create$1$1(id, errorProperty);
746
767
  };
747
- const create$a = (message, result) => {
768
+ const create$j = (message, result) => {
748
769
  return {
749
770
  jsonrpc: Two$1,
750
771
  id: message.id,
@@ -753,7 +774,7 @@ const create$a = (message, result) => {
753
774
  };
754
775
  const getSuccessResponse = (message, result) => {
755
776
  const resultProperty = result ?? null;
756
- return create$a(message, resultProperty);
777
+ return create$j(message, resultProperty);
757
778
  };
758
779
  const getErrorResponseSimple = (id, error) => {
759
780
  return {
@@ -845,36 +866,17 @@ const handleJsonRpcMessage = async (...args) => {
845
866
  throw new JsonRpcError('unexpected message');
846
867
  };
847
868
 
848
- class CommandNotFoundError extends Error {
849
- constructor(command) {
850
- super(`Command not found ${command}`);
851
- this.name = 'CommandNotFoundError';
852
- }
853
- }
854
- const commands = Object.create(null);
855
- const register = commandMap => {
856
- Object.assign(commands, commandMap);
857
- };
858
- const getCommand = key => {
859
- return commands[key];
860
- };
861
- const execute$1 = (command, ...args) => {
862
- const fn = getCommand(command);
863
- if (!fn) {
864
- throw new CommandNotFoundError(command);
865
- }
866
- return fn(...args);
867
- };
868
-
869
869
  const Two = '2.0';
870
- const create$t = (method, params) => {
870
+
871
+ const create$i = (method, params) => {
871
872
  return {
872
873
  jsonrpc: Two,
873
874
  method,
874
875
  params
875
876
  };
876
877
  };
877
- const create$s = (id, method, params) => {
878
+
879
+ const create$h = (id, method, params) => {
878
880
  const message = {
879
881
  id,
880
882
  jsonrpc: Two,
@@ -883,15 +885,14 @@ const create$s = (id, method, params) => {
883
885
  };
884
886
  return message;
885
887
  };
886
- let id = 0;
887
- const create$r = () => {
888
- return ++id;
889
- };
890
888
 
891
- /* eslint-disable n/no-unsupported-features/es-syntax */
889
+ let id$1 = 0;
890
+ const create$g = () => {
891
+ return ++id$1;
892
+ };
892
893
 
893
894
  const registerPromise = map => {
894
- const id = create$r();
895
+ const id = create$g();
895
896
  const {
896
897
  promise,
897
898
  resolve
@@ -909,7 +910,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
909
910
  id,
910
911
  promise
911
912
  } = registerPromise(callbacks);
912
- const message = create$s(id, method, params);
913
+ const message = create$h(id, method, params);
913
914
  if (useSendAndTransfer && ipc.sendAndTransfer) {
914
915
  ipc.sendAndTransfer(message);
915
916
  } else {
@@ -945,12 +946,13 @@ const createRpc = ipc => {
945
946
  * @deprecated
946
947
  */
947
948
  send(method, ...params) {
948
- const message = create$t(method, params);
949
+ const message = create$i(method, params);
949
950
  ipc.send(message);
950
951
  }
951
952
  };
952
953
  return rpc;
953
954
  };
955
+
954
956
  const requiresSocket = () => {
955
957
  return false;
956
958
  };
@@ -965,6 +967,7 @@ const handleMessage = event => {
965
967
  const actualExecute = event?.target?.execute || execute$1;
966
968
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError$1, actualRequiresSocket);
967
969
  };
970
+
968
971
  const handleIpc = ipc => {
969
972
  if ('addEventListener' in ipc) {
970
973
  ipc.addEventListener('message', handleMessage);
@@ -973,6 +976,7 @@ const handleIpc = ipc => {
973
976
  ipc.on('message', handleMessage);
974
977
  }
975
978
  };
979
+
976
980
  const listen$1 = async (module, options) => {
977
981
  const rawIpc = await module.listen(options);
978
982
  if (module.signal) {
@@ -982,8 +986,6 @@ const listen$1 = async (module, options) => {
982
986
  return ipc;
983
987
  };
984
988
 
985
- /* eslint-disable @typescript-eslint/no-misused-promises */
986
-
987
989
  const createSharedLazyRpc = factory => {
988
990
  let rpcPromise;
989
991
  const getOrCreate = () => {
@@ -1011,24 +1013,22 @@ const createSharedLazyRpc = factory => {
1011
1013
  }
1012
1014
  };
1013
1015
  };
1014
- const create$j = async ({
1016
+
1017
+ const create$f = async ({
1015
1018
  commandMap,
1016
1019
  isMessagePortOpen,
1017
1020
  send
1018
1021
  }) => {
1019
1022
  return createSharedLazyRpc(() => {
1020
- return create$3$1({
1023
+ return create$c({
1021
1024
  commandMap,
1022
1025
  isMessagePortOpen,
1023
1026
  send
1024
1027
  });
1025
1028
  });
1026
1029
  };
1027
- const LazyTransferMessagePortRpcParent = {
1028
- __proto__: null,
1029
- create: create$j
1030
- };
1031
- const create$5$1 = async ({
1030
+
1031
+ const create$e = async ({
1032
1032
  commandMap,
1033
1033
  isMessagePortOpen = true,
1034
1034
  messagePort
@@ -1045,20 +1045,18 @@ const create$5$1 = async ({
1045
1045
  messagePort.start();
1046
1046
  return rpc;
1047
1047
  };
1048
- const create$4$1 = async ({
1048
+
1049
+ const create$d = async ({
1049
1050
  commandMap,
1050
1051
  messagePort
1051
1052
  }) => {
1052
- return create$5$1({
1053
+ return create$e({
1053
1054
  commandMap,
1054
1055
  messagePort
1055
1056
  });
1056
1057
  };
1057
- const PlainMessagePortRpcParent = {
1058
- __proto__: null,
1059
- create: create$4$1
1060
- };
1061
- const create$3$1 = async ({
1058
+
1059
+ const create$c = async ({
1062
1060
  commandMap,
1063
1061
  isMessagePortOpen,
1064
1062
  send
@@ -1068,17 +1066,14 @@ const create$3$1 = async ({
1068
1066
  port2
1069
1067
  } = new MessageChannel();
1070
1068
  await send(port1);
1071
- return create$5$1({
1069
+ return create$e({
1072
1070
  commandMap,
1073
1071
  isMessagePortOpen,
1074
1072
  messagePort: port2
1075
1073
  });
1076
1074
  };
1077
- const TransferMessagePortRpcParent = {
1078
- __proto__: null,
1079
- create: create$3$1
1080
- };
1081
- const create$2$1 = async ({
1075
+
1076
+ const create$b = async ({
1082
1077
  commandMap
1083
1078
  }) => {
1084
1079
  // TODO create a commandMap per rpc instance
@@ -1088,29 +1083,6 @@ const create$2$1 = async ({
1088
1083
  const rpc = createRpc(ipc);
1089
1084
  return rpc;
1090
1085
  };
1091
- const WebWorkerRpcClient = {
1092
- __proto__: null,
1093
- create: create$2$1
1094
- };
1095
- const createMockRpc = ({
1096
- commandMap
1097
- }) => {
1098
- const invocations = [];
1099
- const invoke = (method, ...params) => {
1100
- invocations.push([method, ...params]);
1101
- const command = commandMap[method];
1102
- if (!command) {
1103
- throw new Error(`command ${method} not found`);
1104
- }
1105
- return command(...params);
1106
- };
1107
- const mockRpc = {
1108
- invocations,
1109
- invoke,
1110
- invokeAndTransfer: invoke
1111
- };
1112
- return mockRpc;
1113
- };
1114
1086
 
1115
1087
  const Backspace = 1;
1116
1088
  const Tab$1 = 2;
@@ -1181,8 +1153,28 @@ const SetFocusContext$1 = 'Viewlet.setFocusContext';
1181
1153
 
1182
1154
  const FocusEditorText$1 = 12;
1183
1155
 
1156
+ const createMockRpc = ({
1157
+ commandMap
1158
+ }) => {
1159
+ const invocations = [];
1160
+ const invoke = (method, ...params) => {
1161
+ invocations.push([method, ...params]);
1162
+ const command = commandMap[method];
1163
+ if (!command) {
1164
+ throw new Error(`command ${method} not found`);
1165
+ }
1166
+ return command(...params);
1167
+ };
1168
+ const mockRpc = {
1169
+ invocations,
1170
+ invoke,
1171
+ invokeAndTransfer: invoke
1172
+ };
1173
+ return mockRpc;
1174
+ };
1175
+
1184
1176
  const rpcs = Object.create(null);
1185
- const set$e = (id, rpc) => {
1177
+ const set$f = (id, rpc) => {
1186
1178
  rpcs[id] = rpc;
1187
1179
  };
1188
1180
  const get$7 = id => {
@@ -1193,7 +1185,7 @@ const remove$8 = id => {
1193
1185
  };
1194
1186
 
1195
1187
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
1196
- const create$9 = rpcId => {
1188
+ const create$a = rpcId => {
1197
1189
  return {
1198
1190
  async dispose() {
1199
1191
  const rpc = get$7(rpcId);
@@ -1215,7 +1207,7 @@ const create$9 = rpcId => {
1215
1207
  const mockRpc = createMockRpc({
1216
1208
  commandMap
1217
1209
  });
1218
- set$e(rpcId, mockRpc);
1210
+ set$f(rpcId, mockRpc);
1219
1211
  // @ts-ignore
1220
1212
  mockRpc[Symbol.dispose] = () => {
1221
1213
  remove$8(rpcId);
@@ -1224,7 +1216,7 @@ const create$9 = rpcId => {
1224
1216
  return mockRpc;
1225
1217
  },
1226
1218
  set(rpc) {
1227
- set$e(rpcId, rpc);
1219
+ set$f(rpcId, rpc);
1228
1220
  }
1229
1221
  };
1230
1222
  };
@@ -1234,8 +1226,8 @@ const {
1234
1226
  invoke: invoke$f,
1235
1227
  invokeAndTransfer: invokeAndTransfer$2,
1236
1228
  registerMockRpc: registerMockRpc$1,
1237
- set: set$d
1238
- } = create$9(ExtensionHostWorker);
1229
+ set: set$e
1230
+ } = create$a(ExtensionHostWorker);
1239
1231
  const executeReferenceProvider = async (id, offset) => {
1240
1232
  // @ts-ignore
1241
1233
  return invoke$f('ExtensionHostReference.executeReferenceProvider', id, offset);
@@ -1263,21 +1255,21 @@ const ExtensionHost = {
1263
1255
  invoke: invoke$f,
1264
1256
  invokeAndTransfer: invokeAndTransfer$2,
1265
1257
  registerMockRpc: registerMockRpc$1,
1266
- set: set$d
1258
+ set: set$e
1267
1259
  };
1268
1260
 
1269
1261
  const {
1270
1262
  invoke: invoke$e,
1271
- set: set$c
1272
- } = create$9(ExtensionManagementWorker);
1263
+ set: set$d
1264
+ } = create$a(ExtensionManagementWorker);
1273
1265
 
1274
1266
  const {
1275
1267
  dispose: dispose$2,
1276
1268
  invoke: invoke$d,
1277
1269
  invokeAndTransfer: invokeAndTransfer$1,
1278
1270
  registerMockRpc,
1279
- set: set$b
1280
- } = create$9(RendererWorker$1);
1271
+ set: set$c
1272
+ } = create$a(RendererWorker$1);
1281
1273
  const searchFileHtml = async uri => {
1282
1274
  return invoke$d('ExtensionHost.searchFileWithHtml', uri);
1283
1275
  };
@@ -1664,7 +1656,7 @@ const RendererWorker = {
1664
1656
  sendMessagePortToSourceControlWorker,
1665
1657
  sendMessagePortToSyntaxHighlightingWorker: sendMessagePortToSyntaxHighlightingWorker$1,
1666
1658
  sendMessagePortToTextMeasurementWorker,
1667
- set: set$b,
1659
+ set: set$c,
1668
1660
  setAdditionalFocus,
1669
1661
  setColorTheme,
1670
1662
  setExtensionsSearchValue,
@@ -1685,26 +1677,26 @@ const RendererWorker = {
1685
1677
 
1686
1678
  const {
1687
1679
  invoke: invoke$c,
1688
- set: set$a
1689
- } = create$9(OpenerWorker);
1680
+ set: set$b
1681
+ } = create$a(OpenerWorker);
1690
1682
 
1691
1683
  const {
1692
- set: set$9
1693
- } = create$9(IconThemeWorker);
1684
+ set: set$a
1685
+ } = create$a(IconThemeWorker);
1694
1686
 
1695
1687
  const {
1696
1688
  dispose: dispose$1,
1697
1689
  invoke: invoke$b,
1698
1690
  invokeAndTransfer,
1699
- set: set$8
1700
- } = create$9(MarkdownWorker);
1691
+ set: set$9
1692
+ } = create$a(MarkdownWorker);
1701
1693
 
1702
1694
  const SyntaxHighlightingWorker = {
1703
1695
  __proto__: null,
1704
1696
  dispose: dispose$1,
1705
1697
  invoke: invoke$b,
1706
1698
  invokeAndTransfer,
1707
- set: set$8
1699
+ set: set$9
1708
1700
  };
1709
1701
 
1710
1702
  const createLazyRpc = rpcId => {
@@ -1712,7 +1704,7 @@ const createLazyRpc = rpcId => {
1712
1704
  let factory;
1713
1705
  const createRpc = async () => {
1714
1706
  const rpc = await factory();
1715
- set$e(rpcId, rpc);
1707
+ set$f(rpcId, rpc);
1716
1708
  };
1717
1709
  const ensureRpc = async () => {
1718
1710
  if (!rpcPromise) {
@@ -1737,6 +1729,95 @@ const createLazyRpc = rpcId => {
1737
1729
  };
1738
1730
  };
1739
1731
 
1732
+ const toCommandId = key => {
1733
+ const dotIndex = key.indexOf('.');
1734
+ return key.slice(dotIndex + 1);
1735
+ };
1736
+ const create$9 = () => {
1737
+ const states = Object.create(null);
1738
+ const commandMapRef = {};
1739
+ return {
1740
+ clear() {
1741
+ for (const key of Object.keys(states)) {
1742
+ delete states[key];
1743
+ }
1744
+ },
1745
+ diff(uid, modules, numbers) {
1746
+ const {
1747
+ newState,
1748
+ oldState
1749
+ } = states[uid];
1750
+ const diffResult = [];
1751
+ for (let i = 0; i < modules.length; i++) {
1752
+ const fn = modules[i];
1753
+ if (!fn(oldState, newState)) {
1754
+ diffResult.push(numbers[i]);
1755
+ }
1756
+ }
1757
+ return diffResult;
1758
+ },
1759
+ dispose(uid) {
1760
+ delete states[uid];
1761
+ },
1762
+ get(uid) {
1763
+ return states[uid];
1764
+ },
1765
+ getCommandIds() {
1766
+ const keys = Object.keys(commandMapRef);
1767
+ const ids = keys.map(toCommandId);
1768
+ return ids;
1769
+ },
1770
+ getKeys() {
1771
+ return Object.keys(states).map(key => {
1772
+ return Number.parseInt(key);
1773
+ });
1774
+ },
1775
+ registerCommands(commandMap) {
1776
+ Object.assign(commandMapRef, commandMap);
1777
+ },
1778
+ set(uid, oldState, newState) {
1779
+ states[uid] = {
1780
+ newState,
1781
+ oldState
1782
+ };
1783
+ },
1784
+ wrapCommand(fn) {
1785
+ const wrapped = async (uid, ...args) => {
1786
+ const {
1787
+ newState,
1788
+ oldState
1789
+ } = states[uid];
1790
+ const newerState = await fn(newState, ...args);
1791
+ if (oldState === newerState || newState === newerState) {
1792
+ return;
1793
+ }
1794
+ const latestOld = states[uid];
1795
+ const latestNew = {
1796
+ ...latestOld.newState,
1797
+ ...newerState
1798
+ };
1799
+ states[uid] = {
1800
+ newState: latestNew,
1801
+ oldState: latestOld.oldState
1802
+ };
1803
+ };
1804
+ return wrapped;
1805
+ },
1806
+ wrapGetter(fn) {
1807
+ const wrapped = (uid, ...args) => {
1808
+ const {
1809
+ newState
1810
+ } = states[uid];
1811
+ return fn(newState, ...args);
1812
+ };
1813
+ return wrapped;
1814
+ }
1815
+ };
1816
+ };
1817
+ const terminate = () => {
1818
+ globalThis.close();
1819
+ };
1820
+
1740
1821
  // TODO add tests for this
1741
1822
  const activateByEvent = async (event, assetDir, platform) => {
1742
1823
  string(event);
@@ -1753,7 +1834,7 @@ const codeGeneratorAccept = state => {
1753
1834
  const ModuleWorkerAndWorkaroundForChromeDevtoolsBug = 6;
1754
1835
 
1755
1836
  const launchWorker = async (name, url, intializeCommand) => {
1756
- const rpc = await TransferMessagePortRpcParent.create({
1837
+ const rpc = await create$c({
1757
1838
  commandMap: {},
1758
1839
  isMessagePortOpen: true,
1759
1840
  async send(port) {
@@ -1790,7 +1871,7 @@ const invoke$a = async (method, ...params) => {
1790
1871
  return await worker.invoke(method, ...params);
1791
1872
  };
1792
1873
 
1793
- const loadContent$2 = async (state, parentUid) => {
1874
+ const loadContent$3 = async (state, parentUid) => {
1794
1875
  const {
1795
1876
  height,
1796
1877
  uid,
@@ -1808,6 +1889,97 @@ const loadContent$2 = async (state, parentUid) => {
1808
1889
  };
1809
1890
  };
1810
1891
 
1892
+ const {
1893
+ getCommandIds,
1894
+ set: set$8,
1895
+ wrapGetter
1896
+ } = create$9();
1897
+
1898
+ const emptyIncrementalEdits = [];
1899
+
1900
+ const ColorPicker = 41;
1901
+ const EditorCompletion = 9;
1902
+ const Empty = 0;
1903
+ const FindWidget = 16;
1904
+ const FocusEditorHover = 51;
1905
+ const FocusEditorRename$1 = 11;
1906
+ const SourceActions = 38;
1907
+ const FocusCodeGenerator = 52;
1908
+
1909
+ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
1910
+ number(id);
1911
+ const editor = {
1912
+ additionalFocus: 0,
1913
+ assetDir,
1914
+ charWidth: 0,
1915
+ columnWidth: 0,
1916
+ completionState: '',
1917
+ completionTriggerCharacters: [],
1918
+ completionUid: 0,
1919
+ cursorWidth: 2,
1920
+ debugEnabled: false,
1921
+ decorations: [],
1922
+ deltaX: 0,
1923
+ deltaY: 0,
1924
+ diagnostics: [],
1925
+ diagnosticsEnabled: false,
1926
+ differences: [],
1927
+ embeds: [],
1928
+ finalDeltaY: 0,
1929
+ finalY: 0,
1930
+ focus: 0,
1931
+ focused: false,
1932
+ focusKey: Empty,
1933
+ fontFamily: '',
1934
+ fontSize: 0,
1935
+ fontWeight: 0,
1936
+ handleOffsetX: 0,
1937
+ height,
1938
+ highlightedLine: -1,
1939
+ id,
1940
+ incrementalEdits: emptyIncrementalEdits,
1941
+ invalidStartIndex: 0,
1942
+ isAutoClosingBracketsEnabled: false,
1943
+ isAutoClosingQuotesEnabled: false,
1944
+ isAutoClosingTagsEnabled: false,
1945
+ isMonospaceFont: false,
1946
+ isQuickSuggestionsEnabled: false,
1947
+ itemHeight: 20,
1948
+ languageId: '',
1949
+ letterSpacing: 0,
1950
+ lineCache: [],
1951
+ lineNumbers: false,
1952
+ lines: [],
1953
+ longestLineWidth: 0,
1954
+ maxLineY: 0,
1955
+ minimumSliderSize: 20,
1956
+ minLineY: 0,
1957
+ modified: false,
1958
+ numberOfLines: 0,
1959
+ numberOfVisibleLines: 0,
1960
+ platform,
1961
+ primarySelectionIndex: 0,
1962
+ rowHeight: 0,
1963
+ savedSelections: [],
1964
+ scrollBarHeight: 0,
1965
+ scrollBarWidth: 0,
1966
+ selections: new Uint32Array(),
1967
+ tabSize: 0,
1968
+ textInfos: [],
1969
+ tokenizerId: 0,
1970
+ uid: id,
1971
+ undoStack: [],
1972
+ uri,
1973
+ validLines: [],
1974
+ visualDecorations: [],
1975
+ widgets: [],
1976
+ width,
1977
+ x,
1978
+ y
1979
+ };
1980
+ set$8(id, editor, editor);
1981
+ };
1982
+
1811
1983
  // TODO use numeric enum
1812
1984
  const CompositionUpdate = 'compositionUpdate';
1813
1985
  const ContentEditableInput = 'contentEditableInput';
@@ -2984,8 +3156,6 @@ const setDeltaY$2 = async (state, value) => {
2984
3156
  return newEditor2;
2985
3157
  };
2986
3158
 
2987
- const emptyIncrementalEdits = [];
2988
-
2989
3159
  const getIncrementalEdits = async (oldState, newState) => {
2990
3160
  if (!newState.undoStack) {
2991
3161
  return emptyIncrementalEdits;
@@ -3847,15 +4017,6 @@ const {
3847
4017
  set: set$1
3848
4018
  } = ExtensionHost;
3849
4019
 
3850
- const ColorPicker = 41;
3851
- const EditorCompletion = 9;
3852
- const Empty = 0;
3853
- const FindWidget = 16;
3854
- const FocusEditorHover = 51;
3855
- const FocusEditorRename$1 = 11;
3856
- const SourceActions = 38;
3857
- const FocusCodeGenerator = 52;
3858
-
3859
4020
  const getFileExtensionIndex = file => {
3860
4021
  string(file);
3861
4022
  return file.lastIndexOf(Dot);
@@ -4875,7 +5036,7 @@ const create$6 = () => {
4875
5036
  };
4876
5037
 
4877
5038
  const newStateGenerator$6 = (state, parentUid) => {
4878
- return loadContent$2(state, parentUid);
5039
+ return loadContent$3(state, parentUid);
4879
5040
  };
4880
5041
  const openColorPicker = async editor => {
4881
5042
  return addWidgetToEditor(ColorPicker$1, ColorPicker, editor, create$6, newStateGenerator$6);
@@ -7168,7 +7329,7 @@ const launch = async () => {
7168
7329
  return;
7169
7330
  }
7170
7331
  const rpc = await launchFindWidgetWorker();
7171
- set$e(rpcId, rpc);
7332
+ set$f(rpcId, rpc);
7172
7333
  };
7173
7334
  const invoke$3 = async (method, ...params) => {
7174
7335
  const rpc = get$7(rpcId);
@@ -7197,7 +7358,7 @@ const getEditor = editorUid => {
7197
7358
  return newState;
7198
7359
  };
7199
7360
 
7200
- const loadContent$1 = async (state, parentUid) => {
7361
+ const loadContent$2 = async (state, parentUid) => {
7201
7362
  const {
7202
7363
  uid
7203
7364
  } = state;
@@ -7220,7 +7381,7 @@ const loadContent$1 = async (state, parentUid) => {
7220
7381
  };
7221
7382
 
7222
7383
  const newStateGenerator$3 = (state, parentUid) => {
7223
- return loadContent$1(state, parentUid);
7384
+ return loadContent$2(state, parentUid);
7224
7385
  };
7225
7386
  const openFind2 = async editor => {
7226
7387
  const fullFocus = true;
@@ -8159,7 +8320,27 @@ const setSelections = (editor, selections) => {
8159
8320
 
8160
8321
  const setText = (editor, text) => {
8161
8322
  string(text);
8162
- return setText$1(editor, text);
8323
+ const endRowIndex = editor.lines.length - 1;
8324
+ const endColumnIndex = editor.lines.at(-1).length;
8325
+ const start = {
8326
+ columnIndex: 0,
8327
+ rowIndex: 0
8328
+ };
8329
+ const end = {
8330
+ columnIndex: endColumnIndex,
8331
+ rowIndex: endRowIndex
8332
+ };
8333
+ const changes = [{
8334
+ deleted: getSelectionText(editor, {
8335
+ end,
8336
+ start
8337
+ }),
8338
+ end,
8339
+ inserted: splitLines(text),
8340
+ origin: EditorType,
8341
+ start
8342
+ }];
8343
+ return scheduleDocumentAndCursorsSelections(editor, changes);
8163
8344
  };
8164
8345
 
8165
8346
  const create$1 = () => {
@@ -9589,7 +9770,7 @@ const getEditorHoverInfo = async (editorUid, position) => {
9589
9770
  };
9590
9771
  };
9591
9772
 
9592
- const loadContent = async (editorUid, state, position) => {
9773
+ const loadContent$1 = async (editorUid, state, position) => {
9593
9774
  const hoverInfo = await getEditorHoverInfo(editorUid, position);
9594
9775
  if (!hoverInfo) {
9595
9776
  return state;
@@ -10655,12 +10836,12 @@ const handleBeforeInput = (editor, inputType, data) => {
10655
10836
  };
10656
10837
 
10657
10838
  const handleMessagePort = async (port, rpcId) => {
10658
- const rpc = await PlainMessagePortRpcParent.create({
10839
+ const rpc = await create$d({
10659
10840
  commandMap: {},
10660
10841
  messagePort: port
10661
10842
  });
10662
10843
  if (rpcId) {
10663
- set$e(rpcId, rpc);
10844
+ set$f(rpcId, rpc);
10664
10845
  }
10665
10846
  };
10666
10847
 
@@ -10775,7 +10956,7 @@ const sendMessagePortToExtensionHostWorker2 = async (port, initialCommand, rpcId
10775
10956
  const createExtensionHostRpc = async () => {
10776
10957
  try {
10777
10958
  const initialCommand = 'HandleMessagePort.handleMessagePort2';
10778
- const rpc = await TransferMessagePortRpcParent.create({
10959
+ const rpc = await create$c({
10779
10960
  commandMap: {},
10780
10961
  async send(port) {
10781
10962
  await sendMessagePortToExtensionHostWorker2(port, initialCommand, EditorWorker);
@@ -10794,7 +10975,7 @@ const initializeExtensionHost = async () => {
10794
10975
 
10795
10976
  const createExtensionManagementWorkerRpc = async () => {
10796
10977
  try {
10797
- const rpc = await TransferMessagePortRpcParent.create({
10978
+ const rpc = await create$c({
10798
10979
  commandMap: {},
10799
10980
  async send(port) {
10800
10981
  await sendMessagePortToExtensionManagementWorker(port, EditorWorker);
@@ -10809,7 +10990,7 @@ const createExtensionManagementWorkerRpc = async () => {
10809
10990
  const initializeExtensionManagementWorker = async () => {
10810
10991
  try {
10811
10992
  const rpc = await createExtensionManagementWorkerRpc();
10812
- set$c(rpc);
10993
+ set$d(rpc);
10813
10994
  } catch {
10814
10995
  // ignore
10815
10996
  }
@@ -10821,11 +11002,11 @@ const send$2 = port => {
10821
11002
  };
10822
11003
  const initializeOpenerWorker = async () => {
10823
11004
  try {
10824
- const rpc = await LazyTransferMessagePortRpcParent.create({
11005
+ const rpc = await create$f({
10825
11006
  commandMap: {},
10826
11007
  send: send$2
10827
11008
  });
10828
- set$a(rpc);
11009
+ set$b(rpc);
10829
11010
  } catch {
10830
11011
  // ignore
10831
11012
  }
@@ -10845,7 +11026,7 @@ const sendMessagePortToSyntaxHighlightingWorker = async port => {
10845
11026
 
10846
11027
  const createSyntaxHighlightingWorkerRpc = async () => {
10847
11028
  try {
10848
- const rpc = await TransferMessagePortRpcParent.create({
11029
+ const rpc = await create$c({
10849
11030
  commandMap: {},
10850
11031
  send: sendMessagePortToSyntaxHighlightingWorker
10851
11032
  });
@@ -10871,11 +11052,11 @@ const send$1 = port => {
10871
11052
  };
10872
11053
  const initializeTextMeasurementWorker = async () => {
10873
11054
  try {
10874
- const rpc = await LazyTransferMessagePortRpcParent.create({
11055
+ const rpc = await create$f({
10875
11056
  commandMap: {},
10876
11057
  send: send$1
10877
11058
  });
10878
- set$9(rpc);
11059
+ set$a(rpc);
10879
11060
  } catch {
10880
11061
  // ignore
10881
11062
  }
@@ -10894,6 +11075,74 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
10894
11075
  await Promise.all([initializeSyntaxHighlighting(syntaxHighlightingEnabled, syncIncremental), initializeExtensionHost(), initializeExtensionManagementWorker(), initializeTextMeasurementWorker(), initializeOpenerWorker()]);
10895
11076
  };
10896
11077
 
11078
+ const loadContent = async (state, savedState) => {
11079
+ const {
11080
+ assetDir,
11081
+ diagnosticsEnabled,
11082
+ fontFamily,
11083
+ fontSize,
11084
+ fontWeight,
11085
+ height,
11086
+ letterSpacing,
11087
+ platform,
11088
+ uri,
11089
+ width,
11090
+ x,
11091
+ y
11092
+ } = state;
11093
+ // TODO support overwriting language id by setting it explicitly or via settings
11094
+ const charWidth = await measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing);
11095
+ const languages = await getLanguages(platform, assetDir);
11096
+ const computedlanguageId = getLanguageId$1(uri, languages);
11097
+ const newEditor0 = {
11098
+ ...state,
11099
+ charWidth,
11100
+ languageId: computedlanguageId
11101
+ };
11102
+ const content = await readFile(uri);
11103
+
11104
+ // TODO avoid creating intermediate editors here
11105
+ const newEditor1 = setBounds(newEditor0, x, y, width, height, 9);
11106
+ const newEditor2 = setText$1(newEditor1, content);
11107
+ let newEditor3 = newEditor2;
11108
+
11109
+ // Detect links and initialize decorations
11110
+ const linkDecorations = detectAllLinksAsDecorations(newEditor3);
11111
+ const newEditor3WithLinks = {
11112
+ ...newEditor3,
11113
+ decorations: linkDecorations
11114
+ };
11115
+ const syncIncremental = getEnabled();
11116
+ const {
11117
+ differences,
11118
+ textInfos
11119
+ } = await getVisible$1(newEditor3WithLinks, syncIncremental);
11120
+ const newEditor4 = {
11121
+ ...newEditor3WithLinks,
11122
+ differences,
11123
+ focus: FocusEditorText$1,
11124
+ focused: true,
11125
+ textInfos
11126
+ };
11127
+
11128
+ // TODO only sync when needed
11129
+ // e.g. it might not always be necessary to send text to extension host worker
11130
+ // @ts-ignore
11131
+ await invoke$6(TextDocumentSyncFull, uri, id, languageId, content);
11132
+
11133
+ // TODO await promise
11134
+ if (diagnosticsEnabled) {
11135
+ await updateDiagnostics(newEditor4);
11136
+ }
11137
+ const completionsOnTypeRaw = await get$1('editor.completionsOnType');
11138
+ const completionsOnType = Boolean(completionsOnTypeRaw);
11139
+ const newEditor5 = {
11140
+ ...newEditor4,
11141
+ completionsOnType
11142
+ };
11143
+ return newEditor5;
11144
+ };
11145
+
10897
11146
  // TODO move cursor
10898
11147
  // TODO multiple cursors -> vscode removes multiple cursors
10899
11148
  // TODO with selection -> vscode moves whole selection
@@ -11333,6 +11582,15 @@ const renderEventListeners = () => {
11333
11582
  }];
11334
11583
  };
11335
11584
 
11585
+ const saveState = (state, savedState) => {
11586
+ const {
11587
+ lines
11588
+ } = state;
11589
+ return {
11590
+ lines
11591
+ };
11592
+ };
11593
+
11336
11594
  const setDebugEnabled = (state, enabled) => {
11337
11595
  return state;
11338
11596
  };
@@ -11407,7 +11665,7 @@ const wrapCommand = fn => async (editorUid, ...args) => {
11407
11665
  const commandMap = {
11408
11666
  'ActivateByEvent.activateByEvent': activateByEvent,
11409
11667
  'CodeGenerator.accept': codeGeneratorAccept,
11410
- 'ColorPicker.loadContent': loadContent$2,
11668
+ 'ColorPicker.loadContent': loadContent$3,
11411
11669
  'Editor.addCursorAbove': wrapCommand(addCursorAbove),
11412
11670
  'Editor.addCursorBelow': wrapCommand(addCursorBelow),
11413
11671
  'Editor.applyDocumentEdits': wrapCommand(applyDocumentEdits),
@@ -11430,6 +11688,7 @@ const commandMap = {
11430
11688
  'Editor.copyLineDown': wrapCommand(copyLineDown),
11431
11689
  'Editor.copyLineUp': wrapCommand(copyLineUp),
11432
11690
  'Editor.create': createEditor,
11691
+ 'Editor.create2': createEditor2,
11433
11692
  'Editor.cursorCharacterLeft': wrapCommand(cursorCharacterLeft),
11434
11693
  'Editor.cursorCharacterRight': wrapCommand(cursorCharacterRight),
11435
11694
  'Editor.cursorDown': wrapCommand(cursorDown),
@@ -11459,6 +11718,7 @@ const commandMap = {
11459
11718
  'Editor.executeWidgetCommand': wrapCommand(executeWidgetCommand),
11460
11719
  'Editor.findAllReferences': wrapCommand(findAllReferences$1),
11461
11720
  'Editor.format': wrapCommand(format),
11721
+ 'Editor.getCommandIds': getCommandIds,
11462
11722
  'Editor.getDiagnostics': getDiagnostics$1,
11463
11723
  'Editor.getKeyBindings': getKeyBindings,
11464
11724
  'Editor.getKeys': getKeys,
@@ -11513,6 +11773,7 @@ const commandMap = {
11513
11773
  'Editor.indendLess': wrapCommand(indentLess),
11514
11774
  'Editor.indentMore': wrapCommand(indentMore),
11515
11775
  'Editor.insertLineBreak': wrapCommand(insertLineBreak),
11776
+ 'Editor.loadContent': loadContent,
11516
11777
  'Editor.moveLineDown': wrapCommand(moveLineDown),
11517
11778
  'Editor.moveLineUp': wrapCommand(moveLineUp),
11518
11779
  'Editor.moveRectangleSelection': wrapCommand(moveRectangleSelection),
@@ -11534,6 +11795,7 @@ const commandMap = {
11534
11795
  'Editor.replaceRange': wrapCommand(replaceRange),
11535
11796
  'Editor.rerender': wrapCommand(rerender),
11536
11797
  'Editor.save': wrapCommand(save),
11798
+ 'Editor.saveState': wrapGetter(saveState),
11537
11799
  'Editor.selectAll': wrapCommand(selectAll),
11538
11800
  'Editor.selectAllLeft': wrapCommand(editorSelectAllLeft),
11539
11801
  'Editor.selectAllOccurrences': wrapCommand(selectAllOccurrences),
@@ -11565,6 +11827,7 @@ const commandMap = {
11565
11827
  'Editor.showSourceActions3': showSourceActions,
11566
11828
  'Editor.sortLinesAscending': wrapCommand(sortLinesAscending),
11567
11829
  'Editor.tabCompletion': wrapCommand(tabCompletion),
11830
+ 'Editor.terminate': terminate,
11568
11831
  'Editor.toggleBlockComment': wrapCommand(toggleBlockComment),
11569
11832
  'Editor.toggleComment': wrapCommand(toggleComment),
11570
11833
  'Editor.toggleLineComment': wrapCommand(editorToggleLineComment),
@@ -11626,7 +11889,7 @@ const commandMap = {
11626
11889
  'FindWidget.handleReplaceFocus': handleReplaceFocus,
11627
11890
  'FindWidget.handleReplaceInput': handleReplaceInput,
11628
11891
  'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
11629
- 'FindWidget.loadContent': loadContent$1,
11892
+ 'FindWidget.loadContent': loadContent$2,
11630
11893
  'FindWidget.replace': replace,
11631
11894
  'FindWidget.replaceAll': replaceAll,
11632
11895
  'FindWidget.toggleMatchCase': toggleMatchCase,
@@ -11640,10 +11903,11 @@ const commandMap = {
11640
11903
  'Hover.handleSashPointerDown': handleSashPointerDown,
11641
11904
  'Hover.handleSashPointerMove': handleSashPointerMove,
11642
11905
  'Hover.handleSashPointerUp': handleSashPointerUp,
11643
- 'Hover.loadContent': loadContent,
11906
+ 'Hover.loadContent': loadContent$1,
11644
11907
  'Hover.render': renderHover,
11645
11908
  'Initialize.initialize': intialize,
11646
11909
  'Listener.register': registerListener,
11910
+ 'Listener.registerListener': registerListener$1,
11647
11911
  'Listener.unregister': unregisterListener,
11648
11912
  'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker': sendMessagePortToExtensionHostWorker2
11649
11913
  };
@@ -11654,7 +11918,7 @@ const send = port => {
11654
11918
  };
11655
11919
  const createTextMeasurementWorkerRpc = async () => {
11656
11920
  try {
11657
- const rpc = await TransferMessagePortRpcParent.create({
11921
+ const rpc = await create$c({
11658
11922
  commandMap: {},
11659
11923
  send
11660
11924
  });
@@ -11666,10 +11930,10 @@ const createTextMeasurementWorkerRpc = async () => {
11666
11930
 
11667
11931
  const listen = async () => {
11668
11932
  setFactory$1(createTextMeasurementWorkerRpc);
11669
- const rpc = await WebWorkerRpcClient.create({
11933
+ const rpc = await create$b({
11670
11934
  commandMap: commandMap
11671
11935
  });
11672
- set$b(rpc);
11936
+ set$c(rpc);
11673
11937
  };
11674
11938
 
11675
11939
  const CodeGeneratorInput = 'CodeGeneratorInput';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "18.1.0",
3
+ "version": "18.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"