@adecore/editor 0.57.0 → 0.59.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.
@@ -2,8 +2,8 @@ import type { Keymap } from './keymap-table.ts';
2
2
  import type { EditorClickHandler, EditorInlayClickHandler, EditorContextMenu, EditorCopy, EditorKeyHandler, EditorPasteOptions, EditorRunCommand, EditorSelectionRanges, KeyChord } from './types.ts';
3
3
  import type { EditorView } from './view.ts';
4
4
  export interface ControllerOptions {
5
- keymap?: Keymap;
6
- handBack: readonly KeyChord[];
5
+ keymap(): Keymap | undefined;
6
+ handBack(): readonly KeyChord[];
7
7
  apple: boolean;
8
8
  save(): void;
9
9
  blur(): void;
@@ -738,10 +738,10 @@ export class InputController {
738
738
  }
739
739
  }
740
740
  // The app's own shortcuts stay the app's, also where the editor has a binding for the same key.
741
- if (this.options.handBack.some((chord) => chordMatches(chord, event, this.options.apple))) {
741
+ if (this.options.handBack().some((chord) => chordMatches(chord, event, this.options.apple))) {
742
742
  return;
743
743
  }
744
- const action = keyAction(event, this.options.apple, this.options.keymap);
744
+ const action = keyAction(event, this.options.apple, this.options.keymap());
745
745
  if (action) {
746
746
  this.run(action, event);
747
747
  }
package/dist/engine.js CHANGED
@@ -13,6 +13,10 @@ const DEFAULT_LABEL = 'Code editor';
13
13
  const DEFAULT_WIDGET_OWNER = 'default';
14
14
  /* The space a hint's padding keeps clear; a whole pixel count so the pill stays on the pixel grid. */
15
15
  const INLAY_GAP = 4;
16
+ /* A value an app hands over as it is, or as a function the editor asks again each time it needs it. */
17
+ function live(source) {
18
+ return typeof source === 'function' ? source : () => source;
19
+ }
16
20
  class SmartEditor {
17
21
  model;
18
22
  settings;
@@ -67,9 +71,11 @@ class SmartEditor {
67
71
  };
68
72
  this.view = new EditorView(element, this.model, this.settings);
69
73
  this.grammarPreparation = new GrammarPreparation(this.model, () => this.view.grammarChanged());
74
+ const engineHandBack = live(engine.handBack ?? []);
75
+ const mountHandBack = live(options.handBack ?? []);
70
76
  this.controller = new InputController(this.view, {
71
- handBack: [...(engine.handBack ?? []), ...(options.handBack ?? [])],
72
- keymap: engine.keymap,
77
+ handBack: () => [...engineHandBack(), ...mountHandBack()],
78
+ keymap: live(engine.keymap),
73
79
  apple: engine.apple ?? false,
74
80
  save: () => emit(this.saves),
75
81
  blur: () => emit(this.blurs),
package/dist/types.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface EditorFolds {
21
21
  }
22
22
  export type EditorTheme = string;
23
23
  export interface EditorOptions {
24
- readonly handBack?: readonly KeyChord[];
24
+ readonly handBack?: readonly KeyChord[] | (() => readonly KeyChord[]);
25
25
  readonly text: string;
26
26
  readonly language?: string;
27
27
  readonly path?: string;
@@ -488,9 +488,9 @@ export interface LineTokenizer {
488
488
  export type TokenizerSource = (language: string | undefined, theme: EditorTheme, text?: string) => Promise<LineTokenizer | null>;
489
489
  export interface SmartEditorEngineOptions {
490
490
  readonly searchWorker?: EditorSearchClientOptions['workerFactory'];
491
- readonly keymap?: Keymap;
491
+ readonly keymap?: Keymap | (() => Keymap);
492
492
  readonly tokenizer: TokenizerSource;
493
493
  readonly scopeColors?: ScopeColorSource;
494
- readonly handBack?: readonly KeyChord[];
494
+ readonly handBack?: readonly KeyChord[] | (() => readonly KeyChord[]);
495
495
  readonly apple?: boolean;
496
496
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/editor",
3
- "version": "0.57.0",
3
+ "version": "0.59.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -54,8 +54,8 @@
54
54
  "test": "bun test --conditions=source"
55
55
  },
56
56
  "dependencies": {
57
- "@adecore/editor-core": "0.57.0",
58
- "@adecore/utils": "0.57.0",
57
+ "@adecore/editor-core": "0.59.0",
58
+ "@adecore/utils": "0.59.0",
59
59
  "linkedom": "^0.18.14",
60
60
  "shiki": "^4.5.0"
61
61
  },
package/src/controller.ts CHANGED
@@ -27,8 +27,9 @@ import type { EditorView } from './view.ts';
27
27
  import { WheelZoom } from './zoom.ts';
28
28
 
29
29
  export interface ControllerOptions {
30
- keymap?: Keymap;
31
- handBack: readonly KeyChord[];
30
+ /* Read on every key press, so a rebind reaches an editor that is already open. */
31
+ keymap(): Keymap | undefined;
32
+ handBack(): readonly KeyChord[];
32
33
  apple: boolean;
33
34
  save(): void;
34
35
  blur(): void;
@@ -956,11 +957,11 @@ export class InputController {
956
957
  }
957
958
 
958
959
  // The app's own shortcuts stay the app's, also where the editor has a binding for the same key.
959
- if (this.options.handBack.some((chord) => chordMatches(chord, event, this.options.apple))) {
960
+ if (this.options.handBack().some((chord) => chordMatches(chord, event, this.options.apple))) {
960
961
  return;
961
962
  }
962
963
 
963
- const action = keyAction(event, this.options.apple, this.options.keymap);
964
+ const action = keyAction(event, this.options.apple, this.options.keymap());
964
965
 
965
966
  if (action) {
966
967
  this.run(action, event);
package/src/engine.ts CHANGED
@@ -76,6 +76,11 @@ const DEFAULT_WIDGET_OWNER = 'default';
76
76
  /* The space a hint's padding keeps clear; a whole pixel count so the pill stays on the pixel grid. */
77
77
  const INLAY_GAP = 4;
78
78
 
79
+ /* A value an app hands over as it is, or as a function the editor asks again each time it needs it. */
80
+ function live<T>(source: T | (() => T)): () => T {
81
+ return typeof source === 'function' ? (source as () => T) : () => source;
82
+ }
83
+
79
84
  class SmartEditor implements Editor {
80
85
  private readonly model: DocumentModel;
81
86
  private readonly settings: ViewSettings;
@@ -135,9 +140,12 @@ class SmartEditor implements Editor {
135
140
  this.view = new EditorView(element, this.model, this.settings);
136
141
  this.grammarPreparation = new GrammarPreparation(this.model, () => this.view.grammarChanged());
137
142
 
143
+ const engineHandBack = live(engine.handBack ?? []);
144
+ const mountHandBack = live(options.handBack ?? []);
145
+
138
146
  this.controller = new InputController(this.view, {
139
- handBack: [...(engine.handBack ?? []), ...(options.handBack ?? [])],
140
- keymap: engine.keymap,
147
+ handBack: () => [...engineHandBack(), ...mountHandBack()],
148
+ keymap: live(engine.keymap),
141
149
  apple: engine.apple ?? false,
142
150
  save: () => emit(this.saves),
143
151
  blur: () => emit(this.blurs),
package/src/types.ts CHANGED
@@ -66,8 +66,8 @@ export interface EditorFolds {
66
66
  export type EditorTheme = string;
67
67
 
68
68
  export interface EditorOptions {
69
- /* More host shortcuts for this mount, on top of the engine's handBack chords. */
70
- readonly handBack?: readonly KeyChord[];
69
+ /* More host shortcuts for this mount, on top of the engine's handBack chords. A function is asked on every key press. */
70
+ readonly handBack?: readonly KeyChord[] | (() => readonly KeyChord[]);
71
71
  readonly text: string;
72
72
  /* A Shiki language id. Without one, or with one Shiki does not know, it is plain text. */
73
73
  readonly language?: string;
@@ -965,12 +965,13 @@ export type TokenizerSource = (language: string | undefined, theme: EditorTheme,
965
965
  export interface SmartEditorEngineOptions {
966
966
  /* One lazy search worker per mounted editor; regex search is unavailable without it. */
967
967
  readonly searchWorker?: EditorSearchClientOptions['workerFactory'];
968
- readonly keymap?: Keymap;
968
+ /* The key table. A function is asked on every key press, so a rebind reaches the editors that are open. */
969
+ readonly keymap?: Keymap | (() => Keymap);
969
970
  readonly tokenizer: TokenizerSource;
970
971
  /* Without it semantic tokens are ignored and the grammar's colors stand. */
971
972
  readonly scopeColors?: ScopeColorSource;
972
- /* The app's shortcuts that work from anywhere, a text field included; the editor lets them pass untouched. */
973
- readonly handBack?: readonly KeyChord[];
973
+ /* The app's shortcuts that work from anywhere, a text field included; the editor lets them pass untouched. A function is asked on every key press. */
974
+ readonly handBack?: readonly KeyChord[] | (() => readonly KeyChord[]);
974
975
  /* Whether the physical Ctrl and Meta of a shortcut are macOS's. */
975
976
  readonly apple?: boolean;
976
977
  }