@thazhemadam/vim-state 0.1.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.
- package/LICENSE +165 -0
- package/LICENSE.GPL +674 -0
- package/README.md +18 -0
- package/dist/context.d.ts +10 -0
- package/dist/context.js +1 -0
- package/dist/editor/constants.d.ts +13 -0
- package/dist/editor/constants.js +31 -0
- package/dist/editor/index.d.ts +13 -0
- package/dist/editor/index.js +621 -0
- package/dist/editor/operators.d.ts +17 -0
- package/dist/editor/operators.js +85 -0
- package/dist/editor/types.d.ts +118 -0
- package/dist/editor/types.js +1 -0
- package/dist/editor/utils.d.ts +85 -0
- package/dist/editor/utils.js +206 -0
- package/dist/editor.d.ts +1 -0
- package/dist/editor.js +1 -0
- package/dist/events.d.ts +13 -0
- package/dist/events.js +1 -0
- package/dist/history.d.ts +17 -0
- package/dist/history.js +44 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/machine.d.ts +174 -0
- package/dist/machine.js +1235 -0
- package/dist/selectors.d.ts +9 -0
- package/dist/selectors.js +59 -0
- package/dist/state.d.ts +8 -0
- package/dist/state.js +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# vim-state
|
|
2
|
+
|
|
3
|
+
Reusable Vim modal state and host-neutral editing semantics.
|
|
4
|
+
|
|
5
|
+
`vim-state` provides the XState machine, editor host contract, motions, operators, selectors, register types, and linear undo/redo history used by host integrations.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createActor } from "xstate";
|
|
11
|
+
import { vimMachine, type VimEditorApi } from "vim-state";
|
|
12
|
+
|
|
13
|
+
const editor: VimEditorApi = createHostEditor();
|
|
14
|
+
const vim = createActor(vimMachine, { input: { editor } }).start();
|
|
15
|
+
vim.send({ type: "KEY", key: "escape" });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Host integrations must implement `VimEditorHost` or provide a `VimEditorApi`. This package does not depend on any host UI framework.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VimEditorApi, VimOperator, VimRegister, VimVisualSelection } from "./editor.js";
|
|
2
|
+
/** Runtime dependencies and bounded parser data owned by the Vim machine. */
|
|
3
|
+
export interface VimContext {
|
|
4
|
+
editor: VimEditorApi;
|
|
5
|
+
count?: number;
|
|
6
|
+
operator?: VimOperator;
|
|
7
|
+
register?: VimRegister;
|
|
8
|
+
visual?: VimVisualSelection;
|
|
9
|
+
}
|
|
10
|
+
export type VimInput = VimContext;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { VimMotion, VimOperator } from "./types.js";
|
|
2
|
+
/** Terminal/control key bytes forwarded to the host editor. */
|
|
3
|
+
export declare const ARROW_LEFT = "\u001B[D";
|
|
4
|
+
export declare const ARROW_DOWN = "\u001B[B";
|
|
5
|
+
export declare const ARROW_UP = "\u001B[A";
|
|
6
|
+
export declare const ARROW_RIGHT = "\u001B[C";
|
|
7
|
+
export declare const LINE_START = "\u0001";
|
|
8
|
+
export declare const LINE_END = "\u0005";
|
|
9
|
+
export declare const NEWLINE = "\n";
|
|
10
|
+
export declare const DELETE_FORWARD = "\u001B[3~";
|
|
11
|
+
export declare const DELETE_BACKWARD = "";
|
|
12
|
+
export declare const OPERATOR_KEY: Record<VimOperator["name"], string>;
|
|
13
|
+
export declare const NOUN_BY_KEY: Record<string, VimMotion>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Terminal/control key bytes forwarded to the host editor. */
|
|
2
|
+
export const ARROW_LEFT = "\x1b[D";
|
|
3
|
+
export const ARROW_DOWN = "\x1b[B";
|
|
4
|
+
export const ARROW_UP = "\x1b[A";
|
|
5
|
+
export const ARROW_RIGHT = "\x1b[C";
|
|
6
|
+
export const LINE_START = "\x01"; // Ctrl-A
|
|
7
|
+
export const LINE_END = "\x05"; // Ctrl-E
|
|
8
|
+
export const NEWLINE = "\n";
|
|
9
|
+
export const DELETE_FORWARD = "\x1b[3~"; // Delete
|
|
10
|
+
export const DELETE_BACKWARD = "\x7f"; // Backspace
|
|
11
|
+
export const OPERATOR_KEY = {
|
|
12
|
+
delete: "d",
|
|
13
|
+
change: "c",
|
|
14
|
+
yank: "y",
|
|
15
|
+
};
|
|
16
|
+
export const NOUN_BY_KEY = {
|
|
17
|
+
h: "left",
|
|
18
|
+
j: "down",
|
|
19
|
+
k: "up",
|
|
20
|
+
l: "right",
|
|
21
|
+
"0": "lineStart",
|
|
22
|
+
$: "lineEnd",
|
|
23
|
+
"^": "firstNonBlank",
|
|
24
|
+
_: "firstNonBlank",
|
|
25
|
+
w: "nextWord",
|
|
26
|
+
b: "previousWord",
|
|
27
|
+
e: "endOfWord",
|
|
28
|
+
W: "nextBigWord",
|
|
29
|
+
B: "previousBigWord",
|
|
30
|
+
E: "endOfBigWord",
|
|
31
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Constructor, VimEditorApi, VimEditorConfiguration, VimEditorHost } from "./types.js";
|
|
2
|
+
export type { VimCaseTransform, VimEditorApi, VimEditorConfiguration, VimEditorHost, VimEditorOptions, VimFindDirection, VimFindOperation, VimLineTarget, VimMotion, VimNoun, VimOperator, VimOperatorTarget, VimPosition, VimRegister, VimTextObject, VimVisualMode, VimVisualSelection, } from "./types.js";
|
|
3
|
+
export { nounForKey } from "./utils.js";
|
|
4
|
+
/** Editing and configuration operations exposed by a composed Vim editor. */
|
|
5
|
+
export interface VimEditor extends VimEditorApi, VimEditorConfiguration {
|
|
6
|
+
}
|
|
7
|
+
/** Constructor for host editor instances that expose a composed Vim editor. */
|
|
8
|
+
type VimEditorMixinConstructor = Constructor<{
|
|
9
|
+
/** Vim editor exposed by the composed host instance. */
|
|
10
|
+
readonly vimEditor: VimEditor;
|
|
11
|
+
}>;
|
|
12
|
+
/** Return a host editor subclass with reusable Vim editing operations. */
|
|
13
|
+
export declare function VimEditor<TBase extends Constructor<VimEditorHost>>(Base: TBase): TBase & VimEditorMixinConstructor;
|