@lvce-editor/renderer-process 30.73.3 → 30.74.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.
@@ -629,7 +629,7 @@ class CommandNotFoundError extends Error {
629
629
  }
630
630
  }
631
631
  const commands = Object.create(null);
632
- const register$1 = commandMap => {
632
+ const register$2 = commandMap => {
633
633
  Object.assign(commands, commandMap);
634
634
  };
635
635
  const getCommand = key => {
@@ -648,7 +648,7 @@ const callbacks = Object.create(null);
648
648
  const get$c = id => {
649
649
  return callbacks[id];
650
650
  };
651
- const remove$6 = id => {
651
+ const remove$7 = id => {
652
652
  delete callbacks[id];
653
653
  };
654
654
  class JsonRpcError extends Error {
@@ -876,7 +876,7 @@ const resolve = (id, response) => {
876
876
  return;
877
877
  }
878
878
  fn(response);
879
- remove$6(id);
879
+ remove$7(id);
880
880
  };
881
881
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
882
882
  const getErrorType = prettyError => {
@@ -1164,7 +1164,7 @@ const create$E = async ({
1164
1164
  window
1165
1165
  }) => {
1166
1166
  // TODO create a commandMap per rpc instance
1167
- register$1(commandMap);
1167
+ register$2(commandMap);
1168
1168
  const ipc = IpcChildWithElectronWindow$1.wrap(window);
1169
1169
  handleIpc(ipc);
1170
1170
  const rpc = createRpc(ipc);
@@ -1177,7 +1177,7 @@ const create$D = async ({
1177
1177
  messagePort
1178
1178
  }) => {
1179
1179
  // TODO create a commandMap per rpc instance
1180
- register$1(commandMap);
1180
+ register$2(commandMap);
1181
1181
  const rawIpc = await IpcParentWithMessagePort$1$1.create({
1182
1182
  isMessagePortOpen,
1183
1183
  messagePort
@@ -1199,7 +1199,7 @@ const create$C = async ({
1199
1199
  url
1200
1200
  }) => {
1201
1201
  // TODO create a commandMap per rpc instance
1202
- register$1(commandMap);
1202
+ register$2(commandMap);
1203
1203
  const worker = await IpcParentWithModuleWorker$1$1.create({
1204
1204
  name,
1205
1205
  url
@@ -1220,7 +1220,7 @@ const create$B = async ({
1220
1220
  url
1221
1221
  }) => {
1222
1222
  // TODO create a commandMap per rpc instance
1223
- register$1(commandMap);
1223
+ register$2(commandMap);
1224
1224
  const worker = await IpcParentWithModuleWorker$1$1.create({
1225
1225
  name,
1226
1226
  url
@@ -1506,7 +1506,7 @@ const track = (worker, startedIn = state$o.generation, trackedWorker) => {
1506
1506
  metadataById.set(metadata.id, metadata);
1507
1507
  workers$1.set(worker, metadata);
1508
1508
  };
1509
- const remove$5 = worker => {
1509
+ const remove$6 = worker => {
1510
1510
  const metadata = workers$1.get(worker);
1511
1511
  workers$1.delete(worker);
1512
1512
  if (metadata) metadataById.delete(metadata.id);
@@ -2012,6 +2012,82 @@ const initialize = () => {
2012
2012
  }
2013
2013
  };
2014
2014
 
2015
+ const registrations = new Map();
2016
+ const getRegistration = target => {
2017
+ if (!(target instanceof HTMLTextAreaElement) || !target.matches('.EditorInput textarea') || !target.closest('.Editor')) return undefined;
2018
+ const root = target.closest('[id^="Workbench-"]');
2019
+ return root ? registrations.get(root.id) : undefined;
2020
+ };
2021
+ const register$1 = (rootId, id, keymap) => {
2022
+ const root = document.getElementById(rootId);
2023
+ if (!root) throw new Error(`Editor keymap root not found: ${rootId}`);
2024
+ if (registrations.has(rootId)) throw new Error(`Editor keymap already registered: ${rootId}`);
2025
+ if (!Object.hasOwn(keymap.modes, keymap.initialMode)) throw new Error('Unknown initial editor keymap mode');
2026
+ for (const mode of Object.values(keymap.modes)) {
2027
+ for (const binding of Object.values(mode.bindings)) {
2028
+ if (binding.mode !== undefined && !Object.hasOwn(keymap.modes, binding.mode)) throw new Error('Unknown editor keymap mode');
2029
+ }
2030
+ }
2031
+ const cursorStyles = ['--EditorCursorWidth', '--EditorCursorOpacity'].map(name => ({
2032
+ name,
2033
+ priority: root.style.getPropertyPriority(name),
2034
+ value: root.style.getPropertyValue(name)
2035
+ }));
2036
+ if (keymap.cursorStyle !== undefined) {
2037
+ root.style.setProperty('--EditorCursorWidth', keymap.cursorStyle === 'block' ? '1ch' : '2px');
2038
+ root.style.setProperty('--EditorCursorOpacity', keymap.cursorStyle === 'block' ? '0.5' : '1');
2039
+ }
2040
+ const beforeInput = event => {
2041
+ const registration = getRegistration(event.target);
2042
+ if (registration?.keymap.modes[registration.mode]?.captureText) {
2043
+ event.preventDefault();
2044
+ event.stopImmediatePropagation();
2045
+ }
2046
+ };
2047
+ registrations.set(rootId, {
2048
+ beforeInput,
2049
+ cursorStyles,
2050
+ id,
2051
+ keymap,
2052
+ mode: keymap.initialMode,
2053
+ root
2054
+ });
2055
+ root.addEventListener('beforeinput', beforeInput, {
2056
+ capture: true
2057
+ });
2058
+ };
2059
+ const remove$5 = (rootId, id) => {
2060
+ const registration = registrations.get(rootId);
2061
+ if (registration?.id !== id) return;
2062
+ registration.root.removeEventListener('beforeinput', registration.beforeInput, true);
2063
+ if (registration.keymap.cursorStyle !== undefined) {
2064
+ for (const {
2065
+ name,
2066
+ priority,
2067
+ value
2068
+ } of registration.cursorStyles) {
2069
+ if (value) registration.root.style.setProperty(name, value, priority);else registration.root.style.removeProperty(name);
2070
+ }
2071
+ }
2072
+ registrations.delete(rootId);
2073
+ };
2074
+
2075
+ // Resolve mode transitions before the browser can produce the next input event.
2076
+ const handleKeyDown$5 = event => {
2077
+ const registration = getRegistration(event.target);
2078
+ if (!registration || event.altKey || event.ctrlKey || event.metaKey || event.isComposing) return false;
2079
+ const mode = registration.keymap.modes[registration.mode];
2080
+ if (!mode) return false;
2081
+ const binding = Object.hasOwn(mode.bindings, event.key) ? mode.bindings[event.key] : undefined;
2082
+ if (!binding && !(mode.captureText && (event.key.length === 1 || ['Enter', 'Backspace', 'Delete'].includes(event.key)))) return false;
2083
+ event.preventDefault();
2084
+ if (binding?.mode !== undefined) registration.mode = binding.mode;
2085
+ if (binding?.command) {
2086
+ send$1('EditorKeymap.execute', registration.id, binding.command, ...(binding.args || []));
2087
+ }
2088
+ return true;
2089
+ };
2090
+
2015
2091
  const uidSymbol = Symbol('uid');
2016
2092
 
2017
2093
  const getUidTarget = $Element => {
@@ -4431,7 +4507,7 @@ const create$y = async ({
4431
4507
  break;
4432
4508
  }
4433
4509
  } catch (error) {
4434
- remove$5(worker);
4510
+ remove$6(worker);
4435
4511
  worker.terminate();
4436
4512
  throw error;
4437
4513
  }
@@ -4667,7 +4743,7 @@ const create$t = async ({
4667
4743
  const dispose$l = id => {
4668
4744
  const worker = remove$3(id);
4669
4745
  if (worker) {
4670
- remove$5(worker);
4746
+ remove$6(worker);
4671
4747
  worker.terminate();
4672
4748
  }
4673
4749
  };
@@ -7736,6 +7812,7 @@ const isEditableTarget = target => {
7736
7812
  return Boolean(target.closest('input, textarea, [contenteditable]:not([contenteditable="false"])'));
7737
7813
  };
7738
7814
  const handleKeyDown$2 = event => {
7815
+ if (handleKeyDown$5(event)) return;
7739
7816
  if (isNativeButtonActivation(event) || isTerminalTextInput(event)) {
7740
7817
  return;
7741
7818
  }
@@ -12563,6 +12640,8 @@ const commandMap = {
12563
12640
  'Download.downloadFile': downloadFile,
12564
12641
  'DragAndDrop.handleMessagePort': handleMessagePort$1,
12565
12642
  'DropData.get': get$1,
12643
+ 'EditorKeymap.register': register$1,
12644
+ 'EditorKeymap.remove': remove$5,
12566
12645
  'FileHandles.get': get,
12567
12646
  'FilePicker.showDirectoryPicker': showDirectoryPicker,
12568
12647
  'FilePicker.showFilePicker': showFilePicker,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.73.3",
3
+ "version": "30.74.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"