@opentui/core 0.1.55 → 0.1.57

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.
package/index.js CHANGED
@@ -137,7 +137,7 @@ import {
137
137
  white,
138
138
  wrapWithDelegates,
139
139
  yellow
140
- } from "./index-0razn4m6.js";
140
+ } from "./index-crebvcxc.js";
141
141
  // src/text-buffer-view.ts
142
142
  class TextBufferView {
143
143
  lib;
@@ -5413,7 +5413,62 @@ class DiffRenderable extends Renderable {
5413
5413
  }
5414
5414
  }
5415
5415
  }
5416
+ // src/lib/keymapping.ts
5417
+ var defaultKeyAliases = {
5418
+ enter: "return",
5419
+ esc: "escape"
5420
+ };
5421
+ function mergeKeyAliases(defaults, custom) {
5422
+ return { ...defaults, ...custom };
5423
+ }
5424
+ function mergeKeyBindings(defaults, custom) {
5425
+ const map = new Map;
5426
+ for (const binding of defaults) {
5427
+ const key = getKeyBindingKey(binding);
5428
+ map.set(key, binding);
5429
+ }
5430
+ for (const binding of custom) {
5431
+ const key = getKeyBindingKey(binding);
5432
+ map.set(key, binding);
5433
+ }
5434
+ return Array.from(map.values());
5435
+ }
5436
+ function getKeyBindingKey(binding) {
5437
+ return `${binding.name}:${binding.ctrl ? 1 : 0}:${binding.shift ? 1 : 0}:${binding.meta ? 1 : 0}:${binding.super ? 1 : 0}`;
5438
+ }
5439
+ function buildKeyBindingsMap(bindings, aliasMap) {
5440
+ const map = new Map;
5441
+ const aliases = aliasMap || {};
5442
+ for (const binding of bindings) {
5443
+ const key = getKeyBindingKey(binding);
5444
+ map.set(key, binding.action);
5445
+ }
5446
+ for (const binding of bindings) {
5447
+ const normalizedName = aliases[binding.name] || binding.name;
5448
+ if (normalizedName !== binding.name) {
5449
+ const aliasedKey = getKeyBindingKey({ ...binding, name: normalizedName });
5450
+ map.set(aliasedKey, binding.action);
5451
+ }
5452
+ }
5453
+ return map;
5454
+ }
5455
+
5416
5456
  // src/renderables/Input.ts
5457
+ var defaultInputKeybindings = [
5458
+ { name: "left", action: "move-left" },
5459
+ { name: "right", action: "move-right" },
5460
+ { name: "home", action: "move-home" },
5461
+ { name: "end", action: "move-end" },
5462
+ { name: "backspace", action: "delete-backward" },
5463
+ { name: "delete", action: "delete-forward" },
5464
+ { name: "return", action: "submit" },
5465
+ { name: "linefeed", action: "submit" },
5466
+ { name: "a", ctrl: true, action: "move-home" },
5467
+ { name: "e", ctrl: true, action: "move-end" },
5468
+ { name: "f", ctrl: true, action: "move-right" },
5469
+ { name: "b", ctrl: true, action: "move-left" },
5470
+ { name: "d", ctrl: true, action: "delete-forward" }
5471
+ ];
5417
5472
  var InputRenderableEvents;
5418
5473
  ((InputRenderableEvents2) => {
5419
5474
  InputRenderableEvents2["INPUT"] = "input";
@@ -5435,6 +5490,9 @@ class InputRenderable extends Renderable {
5435
5490
  _cursorStyle;
5436
5491
  _maxLength;
5437
5492
  _lastCommittedValue = "";
5493
+ _keyBindingsMap;
5494
+ _keyAliasMap;
5495
+ _keyBindings;
5438
5496
  _defaultOptions = {
5439
5497
  backgroundColor: "transparent",
5440
5498
  textColor: "#FFFFFF",
@@ -5464,6 +5522,10 @@ class InputRenderable extends Renderable {
5464
5522
  this._placeholderColor = parseColor(options.placeholderColor || this._defaultOptions.placeholderColor);
5465
5523
  this._cursorColor = parseColor(options.cursorColor || this._defaultOptions.cursorColor);
5466
5524
  this._cursorStyle = options.cursorStyle || this._defaultOptions.cursorStyle;
5525
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, options.keyAliasMap || {});
5526
+ this._keyBindings = options.keyBindings || [];
5527
+ const mergedBindings = mergeKeyBindings(defaultInputKeybindings, this._keyBindings);
5528
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
5467
5529
  }
5468
5530
  updateCursorPosition() {
5469
5531
  if (!this._focused)
@@ -5594,39 +5656,52 @@ class InputRenderable extends Renderable {
5594
5656
  handleKeyPress(key) {
5595
5657
  const keyName = typeof key === "string" ? key : key.name;
5596
5658
  const keySequence = typeof key === "string" ? key : key.sequence;
5597
- switch (keyName) {
5598
- case "left":
5599
- this.cursorPosition = this._cursorPosition - 1;
5600
- return true;
5601
- case "right":
5602
- this.cursorPosition = this._cursorPosition + 1;
5603
- return true;
5604
- case "home":
5605
- this.cursorPosition = 0;
5606
- return true;
5607
- case "end":
5608
- this.cursorPosition = this._value.length;
5609
- return true;
5610
- case "backspace":
5611
- this.deleteCharacter("backward");
5612
- return true;
5613
- case "delete":
5614
- this.deleteCharacter("forward");
5615
- return true;
5616
- case "return":
5617
- case "linefeed":
5618
- if (this._value !== this._lastCommittedValue) {
5619
- this._lastCommittedValue = this._value;
5620
- this.emit("change" /* CHANGE */, this._value);
5621
- }
5622
- this.emit("enter" /* ENTER */, this._value);
5623
- return true;
5624
- default:
5625
- if (keySequence && keySequence.length === 1 && keySequence.charCodeAt(0) >= 32 && keySequence.charCodeAt(0) <= 126 && (typeof key === "string" || !key.ctrl && !key.meta && !key.super && !key.hyper)) {
5626
- this.insertText(keySequence);
5659
+ const keyCtrl = typeof key === "string" ? false : key.ctrl;
5660
+ const keyShift = typeof key === "string" ? false : key.shift;
5661
+ const keyMeta = typeof key === "string" ? false : key.meta;
5662
+ const keySuper = typeof key === "string" ? false : key.super;
5663
+ const keyHyper = typeof key === "string" ? false : key.hyper;
5664
+ const bindingKey = getKeyBindingKey({
5665
+ name: keyName,
5666
+ ctrl: keyCtrl,
5667
+ shift: keyShift,
5668
+ meta: keyMeta,
5669
+ super: keySuper,
5670
+ action: "move-left"
5671
+ });
5672
+ const action = this._keyBindingsMap.get(bindingKey);
5673
+ if (action) {
5674
+ switch (action) {
5675
+ case "move-left":
5676
+ this.cursorPosition = this._cursorPosition - 1;
5627
5677
  return true;
5628
- }
5629
- break;
5678
+ case "move-right":
5679
+ this.cursorPosition = this._cursorPosition + 1;
5680
+ return true;
5681
+ case "move-home":
5682
+ this.cursorPosition = 0;
5683
+ return true;
5684
+ case "move-end":
5685
+ this.cursorPosition = this._value.length;
5686
+ return true;
5687
+ case "delete-backward":
5688
+ this.deleteCharacter("backward");
5689
+ return true;
5690
+ case "delete-forward":
5691
+ this.deleteCharacter("forward");
5692
+ return true;
5693
+ case "submit":
5694
+ if (this._value !== this._lastCommittedValue) {
5695
+ this._lastCommittedValue = this._value;
5696
+ this.emit("change" /* CHANGE */, this._value);
5697
+ }
5698
+ this.emit("enter" /* ENTER */, this._value);
5699
+ return true;
5700
+ }
5701
+ }
5702
+ if (keySequence && keySequence.length === 1 && keySequence.charCodeAt(0) >= 32 && keySequence.charCodeAt(0) <= 126 && !keyCtrl && !keyMeta && !keySuper && !keyHyper) {
5703
+ this.insertText(keySequence);
5704
+ return true;
5630
5705
  }
5631
5706
  return false;
5632
5707
  }
@@ -5706,6 +5781,16 @@ class InputRenderable extends Renderable {
5706
5781
  this._ctx.setCursorPosition(0, 0, false);
5707
5782
  }
5708
5783
  }
5784
+ set keyBindings(bindings) {
5785
+ this._keyBindings = bindings;
5786
+ const mergedBindings = mergeKeyBindings(defaultInputKeybindings, bindings);
5787
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
5788
+ }
5789
+ set keyAliasMap(aliases) {
5790
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, aliases);
5791
+ const mergedBindings = mergeKeyBindings(defaultInputKeybindings, this._keyBindings);
5792
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
5793
+ }
5709
5794
  }
5710
5795
  // src/renderables/Slider.ts
5711
5796
  var defaultThumbBackgroundColor = RGBA.fromHex("#9a9ea3");
@@ -6858,6 +6943,16 @@ class ScrollBoxRenderable extends BoxRenderable {
6858
6943
  }
6859
6944
  }
6860
6945
  // src/renderables/Select.ts
6946
+ var defaultSelectKeybindings = [
6947
+ { name: "up", action: "move-up" },
6948
+ { name: "k", action: "move-up" },
6949
+ { name: "down", action: "move-down" },
6950
+ { name: "j", action: "move-down" },
6951
+ { name: "up", shift: true, action: "move-up-fast" },
6952
+ { name: "down", shift: true, action: "move-down-fast" },
6953
+ { name: "return", action: "select-current" },
6954
+ { name: "linefeed", action: "select-current" }
6955
+ ];
6861
6956
  var SelectRenderableEvents;
6862
6957
  ((SelectRenderableEvents2) => {
6863
6958
  SelectRenderableEvents2["SELECTION_CHANGED"] = "selectionChanged";
@@ -6886,6 +6981,9 @@ class SelectRenderable extends Renderable {
6886
6981
  linesPerItem;
6887
6982
  fontHeight;
6888
6983
  _fastScrollStep;
6984
+ _keyBindingsMap;
6985
+ _keyAliasMap;
6986
+ _keyBindings;
6889
6987
  _defaultOptions = {
6890
6988
  backgroundColor: "transparent",
6891
6989
  textColor: "#FFFFFF",
@@ -6925,6 +7023,10 @@ class SelectRenderable extends Renderable {
6925
7023
  this._descriptionColor = parseColor(options.descriptionColor || this._defaultOptions.descriptionColor);
6926
7024
  this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || this._defaultOptions.selectedDescriptionColor);
6927
7025
  this._fastScrollStep = options.fastScrollStep || this._defaultOptions.fastScrollStep;
7026
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, options.keyAliasMap || {});
7027
+ this._keyBindings = options.keyBindings || [];
7028
+ const mergedBindings = mergeKeyBindings(defaultSelectKeybindings, this._keyBindings);
7029
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
6928
7030
  this.requestRender();
6929
7031
  }
6930
7032
  renderSelf(buffer, deltaTime) {
@@ -7065,20 +7167,37 @@ class SelectRenderable extends Renderable {
7065
7167
  }
7066
7168
  handleKeyPress(key) {
7067
7169
  const keyName = typeof key === "string" ? key : key.name;
7068
- const isShift = typeof key !== "string" && key.shift;
7069
- switch (keyName) {
7070
- case "up":
7071
- case "k":
7072
- this.moveUp(isShift ? this._fastScrollStep : 1);
7073
- return true;
7074
- case "down":
7075
- case "j":
7076
- this.moveDown(isShift ? this._fastScrollStep : 1);
7077
- return true;
7078
- case "return":
7079
- case "linefeed":
7080
- this.selectCurrent();
7081
- return true;
7170
+ const keyCtrl = typeof key === "string" ? false : key.ctrl;
7171
+ const keyShift = typeof key === "string" ? false : key.shift;
7172
+ const keyMeta = typeof key === "string" ? false : key.meta;
7173
+ const keySuper = typeof key === "string" ? false : key.super;
7174
+ const bindingKey = getKeyBindingKey({
7175
+ name: keyName,
7176
+ ctrl: keyCtrl,
7177
+ shift: keyShift,
7178
+ meta: keyMeta,
7179
+ super: keySuper,
7180
+ action: "move-up"
7181
+ });
7182
+ const action = this._keyBindingsMap.get(bindingKey);
7183
+ if (action) {
7184
+ switch (action) {
7185
+ case "move-up":
7186
+ this.moveUp(1);
7187
+ return true;
7188
+ case "move-down":
7189
+ this.moveDown(1);
7190
+ return true;
7191
+ case "move-up-fast":
7192
+ this.moveUp(this._fastScrollStep);
7193
+ return true;
7194
+ case "move-down-fast":
7195
+ this.moveDown(this._fastScrollStep);
7196
+ return true;
7197
+ case "select-current":
7198
+ this.selectCurrent();
7199
+ return true;
7200
+ }
7082
7201
  }
7083
7202
  return false;
7084
7203
  }
@@ -7184,6 +7303,16 @@ class SelectRenderable extends Renderable {
7184
7303
  set fastScrollStep(step) {
7185
7304
  this._fastScrollStep = step;
7186
7305
  }
7306
+ set keyBindings(bindings) {
7307
+ this._keyBindings = bindings;
7308
+ const mergedBindings = mergeKeyBindings(defaultSelectKeybindings, bindings);
7309
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
7310
+ }
7311
+ set keyAliasMap(aliases) {
7312
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, aliases);
7313
+ const mergedBindings = mergeKeyBindings(defaultSelectKeybindings, this._keyBindings);
7314
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
7315
+ }
7187
7316
  set selectedIndex(value) {
7188
7317
  const newIndex = value ?? this._defaultOptions.selectedIndex;
7189
7318
  const clampedIndex = this._options.length > 0 ? Math.min(Math.max(0, newIndex), this._options.length - 1) : 0;
@@ -7195,6 +7324,14 @@ class SelectRenderable extends Renderable {
7195
7324
  }
7196
7325
  }
7197
7326
  // src/renderables/TabSelect.ts
7327
+ var defaultTabSelectKeybindings = [
7328
+ { name: "left", action: "move-left" },
7329
+ { name: "[", action: "move-left" },
7330
+ { name: "right", action: "move-right" },
7331
+ { name: "]", action: "move-right" },
7332
+ { name: "return", action: "select-current" },
7333
+ { name: "linefeed", action: "select-current" }
7334
+ ];
7198
7335
  var TabSelectRenderableEvents;
7199
7336
  ((TabSelectRenderableEvents2) => {
7200
7337
  TabSelectRenderableEvents2["SELECTION_CHANGED"] = "selectionChanged";
@@ -7229,6 +7366,9 @@ class TabSelectRenderable extends Renderable {
7229
7366
  _showDescription;
7230
7367
  _showUnderline;
7231
7368
  _wrapSelection;
7369
+ _keyBindingsMap;
7370
+ _keyAliasMap;
7371
+ _keyBindings;
7232
7372
  constructor(ctx, options) {
7233
7373
  const calculatedHeight = calculateDynamicHeight(options.showUnderline ?? true, options.showDescription ?? true);
7234
7374
  super(ctx, { ...options, height: calculatedHeight, buffered: true });
@@ -7246,6 +7386,10 @@ class TabSelectRenderable extends Renderable {
7246
7386
  this._selectedBackgroundColor = parseColor(options.selectedBackgroundColor || "#334455");
7247
7387
  this._selectedTextColor = parseColor(options.selectedTextColor || "#FFFF00");
7248
7388
  this._selectedDescriptionColor = parseColor(options.selectedDescriptionColor || "#CCCCCC");
7389
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, options.keyAliasMap || {});
7390
+ this._keyBindings = options.keyBindings || [];
7391
+ const mergedBindings = mergeKeyBindings(defaultTabSelectKeybindings, this._keyBindings);
7392
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
7249
7393
  }
7250
7394
  calculateDynamicHeight() {
7251
7395
  return calculateDynamicHeight(this._showUnderline, this._showDescription);
@@ -7396,19 +7540,31 @@ class TabSelectRenderable extends Renderable {
7396
7540
  }
7397
7541
  handleKeyPress(key) {
7398
7542
  const keyName = typeof key === "string" ? key : key.name;
7399
- switch (keyName) {
7400
- case "left":
7401
- case "[":
7402
- this.moveLeft();
7403
- return true;
7404
- case "right":
7405
- case "]":
7406
- this.moveRight();
7407
- return true;
7408
- case "return":
7409
- case "linefeed":
7410
- this.selectCurrent();
7411
- return true;
7543
+ const keyCtrl = typeof key === "string" ? false : key.ctrl;
7544
+ const keyShift = typeof key === "string" ? false : key.shift;
7545
+ const keyMeta = typeof key === "string" ? false : key.meta;
7546
+ const keySuper = typeof key === "string" ? false : key.super;
7547
+ const bindingKey = getKeyBindingKey({
7548
+ name: keyName,
7549
+ ctrl: keyCtrl,
7550
+ shift: keyShift,
7551
+ meta: keyMeta,
7552
+ super: keySuper,
7553
+ action: "move-left"
7554
+ });
7555
+ const action = this._keyBindingsMap.get(bindingKey);
7556
+ if (action) {
7557
+ switch (action) {
7558
+ case "move-left":
7559
+ this.moveLeft();
7560
+ return true;
7561
+ case "move-right":
7562
+ this.moveRight();
7563
+ return true;
7564
+ case "select-current":
7565
+ this.selectCurrent();
7566
+ return true;
7567
+ }
7412
7568
  }
7413
7569
  return false;
7414
7570
  }
@@ -7497,6 +7653,16 @@ class TabSelectRenderable extends Renderable {
7497
7653
  this.updateScrollOffset();
7498
7654
  this.requestRender();
7499
7655
  }
7656
+ set keyBindings(bindings) {
7657
+ this._keyBindings = bindings;
7658
+ const mergedBindings = mergeKeyBindings(defaultTabSelectKeybindings, bindings);
7659
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
7660
+ }
7661
+ set keyAliasMap(aliases) {
7662
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, aliases);
7663
+ const mergedBindings = mergeKeyBindings(defaultTabSelectKeybindings, this._keyBindings);
7664
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
7665
+ }
7500
7666
  }
7501
7667
  // src/renderables/EditBufferRenderable.ts
7502
7668
  class EditBufferRenderable extends Renderable {
@@ -7990,31 +8156,6 @@ class EditBufferRenderable extends Renderable {
7990
8156
  }
7991
8157
  }
7992
8158
 
7993
- // src/lib/keymapping.ts
7994
- function mergeKeyBindings(defaults, custom) {
7995
- const map = new Map;
7996
- for (const binding of defaults) {
7997
- const key = getKeyBindingKey(binding);
7998
- map.set(key, binding);
7999
- }
8000
- for (const binding of custom) {
8001
- const key = getKeyBindingKey(binding);
8002
- map.set(key, binding);
8003
- }
8004
- return Array.from(map.values());
8005
- }
8006
- function getKeyBindingKey(binding) {
8007
- return `${binding.name}:${binding.ctrl ? 1 : 0}:${binding.shift ? 1 : 0}:${binding.meta ? 1 : 0}:${binding.super ? 1 : 0}`;
8008
- }
8009
- function buildKeyBindingsMap(bindings) {
8010
- const map = new Map;
8011
- for (const binding of bindings) {
8012
- const key = getKeyBindingKey(binding);
8013
- map.set(key, binding.action);
8014
- }
8015
- return map;
8016
- }
8017
-
8018
8159
  // src/renderables/Textarea.ts
8019
8160
  var defaultTextareaKeybindings = [
8020
8161
  { name: "left", action: "move-left" },
@@ -8067,6 +8208,8 @@ class TextareaRenderable extends EditBufferRenderable {
8067
8208
  _focusedBackgroundColor;
8068
8209
  _focusedTextColor;
8069
8210
  _keyBindingsMap;
8211
+ _keyAliasMap;
8212
+ _keyBindings;
8070
8213
  _actionHandlers;
8071
8214
  _initialValueSet = false;
8072
8215
  _submitListener = undefined;
@@ -8090,8 +8233,10 @@ class TextareaRenderable extends EditBufferRenderable {
8090
8233
  this._focusedBackgroundColor = parseColor(options.focusedBackgroundColor || options.backgroundColor || defaults.focusedBackgroundColor);
8091
8234
  this._focusedTextColor = parseColor(options.focusedTextColor || options.textColor || defaults.focusedTextColor);
8092
8235
  this._placeholder = options.placeholder ?? defaults.placeholder;
8093
- const mergedBindings = mergeKeyBindings(defaultTextareaKeybindings, options.keyBindings || []);
8094
- this._keyBindingsMap = buildKeyBindingsMap(mergedBindings);
8236
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, options.keyAliasMap || {});
8237
+ this._keyBindings = options.keyBindings || [];
8238
+ const mergedBindings = mergeKeyBindings(defaultTextareaKeybindings, this._keyBindings);
8239
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
8095
8240
  this._actionHandlers = this.buildActionHandlers();
8096
8241
  this._submitListener = options.onSubmit;
8097
8242
  if (options.initialValue) {
@@ -8463,8 +8608,14 @@ class TextareaRenderable extends EditBufferRenderable {
8463
8608
  return this._submitListener;
8464
8609
  }
8465
8610
  set keyBindings(bindings) {
8611
+ this._keyBindings = bindings;
8466
8612
  const mergedBindings = mergeKeyBindings(defaultTextareaKeybindings, bindings);
8467
- this._keyBindingsMap = buildKeyBindingsMap(mergedBindings);
8613
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
8614
+ }
8615
+ set keyAliasMap(aliases) {
8616
+ this._keyAliasMap = mergeKeyAliases(defaultKeyAliases, aliases);
8617
+ const mergedBindings = mergeKeyBindings(defaultTextareaKeybindings, this._keyBindings);
8618
+ this._keyBindingsMap = buildKeyBindingsMap(mergedBindings, this._keyAliasMap);
8468
8619
  }
8469
8620
  get extmarks() {
8470
8621
  return this.editorView.extmarks;
@@ -8657,5 +8808,5 @@ export {
8657
8808
  ASCIIFont
8658
8809
  };
8659
8810
 
8660
- //# debugId=C184A1CDDE59DFEA64756E2164756E21
8811
+ //# debugId=0B9337575CE949C264756E2164756E21
8661
8812
  //# sourceMappingURL=index.js.map