dirvi-lib 0.2.0 → 0.4.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.
Files changed (58) hide show
  1. package/dist/application/intent-to-effect-no-state.test.d.ts +2 -0
  2. package/dist/application/intent-to-effect-no-state.test.d.ts.map +1 -0
  3. package/dist/application/intent-to-effect-no-state.test.js +178 -0
  4. package/dist/application/intent-to-effect.d.ts +8 -0
  5. package/dist/application/intent-to-effect.d.ts.map +1 -0
  6. package/dist/application/intent-to-effect.js +142 -0
  7. package/dist/application/intent-to-effect.test-no-state.d.ts +2 -0
  8. package/dist/application/intent-to-effect.test-no-state.d.ts.map +1 -0
  9. package/dist/application/intent-to-effect.test-no-state.js +178 -0
  10. package/dist/application/user-input-to-intent.d.ts +8 -0
  11. package/dist/application/user-input-to-intent.d.ts.map +1 -0
  12. package/dist/application/user-input-to-intent.js +98 -0
  13. package/dist/application/user-input-to-intent.test.d.ts +2 -0
  14. package/dist/application/user-input-to-intent.test.d.ts.map +1 -0
  15. package/dist/application/user-input-to-intent.test.js +125 -0
  16. package/dist/domain/cursor.d.ts +19 -0
  17. package/dist/domain/cursor.d.ts.map +1 -0
  18. package/dist/domain/cursor.js +46 -0
  19. package/dist/domain/display-row.d.ts +31 -24
  20. package/dist/domain/display-row.d.ts.map +1 -1
  21. package/dist/domain/display-row.js +22 -16
  22. package/dist/domain/effect.d.ts +48 -0
  23. package/dist/domain/effect.d.ts.map +1 -0
  24. package/dist/domain/effect.js +1 -0
  25. package/dist/domain/fold-node.d.ts +25 -0
  26. package/dist/domain/fold-node.d.ts.map +1 -0
  27. package/dist/domain/fold-node.js +93 -0
  28. package/dist/domain/input-state.d.ts +10 -0
  29. package/dist/domain/input-state.d.ts.map +1 -0
  30. package/dist/domain/input-state.js +1 -0
  31. package/dist/domain/intent.d.ts +34 -0
  32. package/dist/domain/intent.d.ts.map +1 -0
  33. package/dist/domain/intent.js +1 -0
  34. package/dist/domain/navigation-node.d.ts +58 -0
  35. package/dist/domain/navigation-node.d.ts.map +1 -0
  36. package/dist/domain/navigation-node.js +210 -0
  37. package/dist/domain/state.d.ts +12 -0
  38. package/dist/domain/state.d.ts.map +1 -0
  39. package/dist/domain/state.js +12 -0
  40. package/dist/domain/unix-entry.d.ts +39 -13
  41. package/dist/domain/unix-entry.d.ts.map +1 -1
  42. package/dist/domain/unix-entry.js +101 -8
  43. package/dist/domain/unix-path.d.ts +1 -1
  44. package/dist/domain/unix-path.js +9 -6
  45. package/dist/domain/user-input.d.ts +27 -0
  46. package/dist/domain/user-input.d.ts.map +1 -0
  47. package/dist/domain/user-input.js +1 -0
  48. package/dist/index.d.ts +10 -2
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +9 -1
  51. package/dist/infrastructure/get-cwd.d.ts +1 -1
  52. package/dist/infrastructure/get-cwd.js +12 -10
  53. package/dist/infrastructure/get-dir-lazy-entries.d.ts +4 -2
  54. package/dist/infrastructure/get-dir-lazy-entries.js +34 -28
  55. package/package.json +4 -2
  56. package/dist/domain/view.d.ts +0 -17
  57. package/dist/domain/view.d.ts.map +0 -1
  58. package/dist/domain/view.js +0 -6
@@ -0,0 +1,125 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { userInputToIntent } from './user-input-to-intent.js';
3
+ function normalInputState(normalBuffer = '') {
4
+ return {
5
+ inputMode: 'normal',
6
+ normalBuffer,
7
+ };
8
+ }
9
+ function commandInputState(commandLine = ':') {
10
+ return {
11
+ inputMode: 'command',
12
+ commandLine,
13
+ };
14
+ }
15
+ describe('userInputToIntent', () => {
16
+ describe('normal mode', () => {
17
+ it.each([
18
+ ['l', { intentType: 'normalRight' }],
19
+ ['h', { intentType: 'normalLeft' }],
20
+ ['j', { intentType: 'normalDown' }],
21
+ ['k', { intentType: 'normalUp' }],
22
+ [':', { intentType: 'enterCommandLineMode' }],
23
+ ])('converts "%s" to the expected intent', (character, expected) => {
24
+ const userInput = {
25
+ userInputType: 'character',
26
+ string: character,
27
+ };
28
+ expect(userInputToIntent(userInput, normalInputState())).toEqual(
29
+ expected,
30
+ );
31
+ });
32
+ it('adds an unrecognized character to the normal buffer', () => {
33
+ const userInput = {
34
+ userInputType: 'character',
35
+ string: 'g',
36
+ };
37
+ expect(userInputToIntent(userInput, normalInputState())).toEqual({
38
+ intentType: 'setNormalBuffer',
39
+ normalBuffer: 'g',
40
+ });
41
+ });
42
+ it('appends a character to an existing normal buffer', () => {
43
+ const userInput = {
44
+ userInputType: 'character',
45
+ string: 'g',
46
+ };
47
+ expect(userInputToIntent(userInput, normalInputState('2'))).toEqual({
48
+ intentType: 'setNormalBuffer',
49
+ normalBuffer: '2g',
50
+ });
51
+ });
52
+ it('clears the normal buffer when Escape is pressed', () => {
53
+ const userInput = {
54
+ userInputType: 'esc',
55
+ };
56
+ expect(userInputToIntent(userInput, normalInputState('gg'))).toEqual({
57
+ intentType: 'setNormalBuffer',
58
+ normalBuffer: '',
59
+ });
60
+ });
61
+ it.each([
62
+ ['rightArrow', 'normalRight'],
63
+ ['leftArrow', 'normalLeft'],
64
+ ['downArrow', 'normalDown'],
65
+ ['upArrow', 'normalUp'],
66
+ ])('converts %s to %s', (userInputType, intentType) => {
67
+ const userInput = {
68
+ userInputType,
69
+ };
70
+ expect(userInputToIntent(userInput, normalInputState())).toEqual({
71
+ intentType,
72
+ });
73
+ });
74
+ it('does not enter command-line mode when the normal buffer is non-empty', () => {
75
+ const userInput = {
76
+ userInputType: 'character',
77
+ string: ':',
78
+ };
79
+ expect(userInputToIntent(userInput, normalInputState('g'))).toEqual({
80
+ intentType: 'setNormalBuffer',
81
+ normalBuffer: 'g:',
82
+ });
83
+ });
84
+ });
85
+ describe('command-line mode', () => {
86
+ it('appends a character to the command line', () => {
87
+ const userInput = {
88
+ userInputType: 'character',
89
+ string: 'w',
90
+ };
91
+ expect(userInputToIntent(userInput, commandInputState(':'))).toEqual({
92
+ intentType: 'setCommandLine',
93
+ commandLine: ':w',
94
+ });
95
+ });
96
+ it('executes the command line when Enter is pressed', () => {
97
+ const userInput = {
98
+ userInputType: 'enter',
99
+ };
100
+ expect(userInputToIntent(userInput, commandInputState(':w'))).toEqual({
101
+ intentType: 'executeCommandLine',
102
+ commandLine: ':w',
103
+ });
104
+ });
105
+ it('exits command-line mode when Escape is pressed', () => {
106
+ const userInput = {
107
+ userInputType: 'esc',
108
+ };
109
+ expect(userInputToIntent(userInput, commandInputState(':w'))).toEqual({
110
+ intentType: 'exitCommandLineMode',
111
+ });
112
+ });
113
+ it.each(['rightArrow', 'leftArrow', 'downArrow', 'upArrow'])(
114
+ 'ignores %s in command-line mode',
115
+ (userInputType) => {
116
+ const userInput = {
117
+ userInputType,
118
+ };
119
+ expect(
120
+ userInputToIntent(userInput, commandInputState()),
121
+ ).toBeUndefined();
122
+ },
123
+ );
124
+ });
125
+ });
@@ -0,0 +1,19 @@
1
+ import { UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
+ import { DisplayRow } from './display-row.js';
3
+ export type Cursor =
4
+ | {
5
+ kind: 'entry';
6
+ parentPath: UnixEntryPath;
7
+ entryName: UnixEntryName;
8
+ }
9
+ | {
10
+ kind: 'fold';
11
+ parentPath: UnixEntryPath;
12
+ };
13
+ export declare const Cursor: {
14
+ equal(left: Cursor, right: Cursor): boolean;
15
+ matchesDisplayRow(cursor: Cursor, row: DisplayRow): boolean;
16
+ fromDisplayRow(row: DisplayRow): Cursor;
17
+ getPath(cursor: Cursor): UnixEntryPath | undefined;
18
+ };
19
+ //# sourceMappingURL=cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/domain/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,MAAM,GACd;IACE,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,aAAa,CAAC;IAC1B,SAAS,EAAE,aAAa,CAAC;CAC1B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEN,eAAO,MAAM,MAAM;gBACL,MAAM,SAAS,MAAM,GAAG,OAAO;8BAgBjB,MAAM,OAAO,UAAU,GAAG,OAAO;wBAevC,UAAU,GAAG,MAAM;oBAevB,MAAM,GAAG,aAAa,GAAG,SAAS;CAOnD,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { UnixEntryPath } from './unix-entry.js';
2
+ export const Cursor = {
3
+ equal(left, right) {
4
+ if (left.kind !== right.kind) {
5
+ return false;
6
+ }
7
+ if (!UnixEntryPath.equal(left.parentPath, right.parentPath)) {
8
+ return false;
9
+ }
10
+ if (left.kind === 'entry' && right.kind === 'entry') {
11
+ return left.entryName === right.entryName;
12
+ }
13
+ return true;
14
+ },
15
+ matchesDisplayRow(cursor, row) {
16
+ if (cursor.kind === 'entry' && row.kind === 'entry') {
17
+ return (
18
+ UnixEntryPath.equal(cursor.parentPath, row.parentPath) &&
19
+ cursor.entryName === row.entry.name
20
+ );
21
+ }
22
+ if (cursor.kind === 'fold' && row.kind === 'fold') {
23
+ return UnixEntryPath.equal(cursor.parentPath, row.parentPath);
24
+ }
25
+ return false;
26
+ },
27
+ fromDisplayRow(row) {
28
+ if (row.kind === 'entry') {
29
+ return {
30
+ kind: 'entry',
31
+ parentPath: row.parentPath,
32
+ entryName: row.entry.name,
33
+ };
34
+ }
35
+ return {
36
+ kind: 'fold',
37
+ parentPath: row.parentPath,
38
+ };
39
+ },
40
+ getPath(cursor) {
41
+ if (cursor.kind === 'fold') {
42
+ return undefined;
43
+ }
44
+ return [...cursor.parentPath, cursor.entryName];
45
+ },
46
+ };
@@ -1,27 +1,34 @@
1
- import type { UnixEntry, UnixEntryName } from './unix-entry.js';
1
+ import { UnixEntry, UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
2
  import type { UnixPath } from './unix-path.js';
3
- export type EntryPath = UnixEntryName[];
4
- export declare function pathsEqual(left: EntryPath, right: EntryPath): boolean;
5
- export type DisplayEntry = {
6
- kind: 'file';
7
- name: UnixEntryName;
8
- } | {
9
- kind: 'symlink';
10
- name: UnixEntryName;
11
- target: UnixPath;
12
- } | {
13
- kind: 'directory';
14
- name: UnixEntryName;
3
+ export type DisplayEntry =
4
+ | {
5
+ kind: 'file';
6
+ name: UnixEntryName;
7
+ }
8
+ | {
9
+ kind: 'symlink';
10
+ name: UnixEntryName;
11
+ target: UnixPath;
12
+ }
13
+ | {
14
+ kind: 'directory';
15
+ name: UnixEntryName;
16
+ };
17
+ export declare const DisplayEntry: {
18
+ fromUnixEntry(entry: UnixEntry): DisplayEntry;
15
19
  };
16
- export declare function unixEntryToDisplayEntry(entry: UnixEntry): DisplayEntry;
17
- export type DisplayRow = {
18
- kind: 'entry';
19
- parentPath: EntryPath;
20
- entry: DisplayEntry;
21
- } | {
22
- kind: 'fold';
23
- parentPath: EntryPath;
24
- entryNames: UnixEntryName[];
20
+ export type DisplayRow =
21
+ | {
22
+ kind: 'entry';
23
+ parentPath: UnixEntryPath;
24
+ entry: DisplayEntry;
25
+ }
26
+ | {
27
+ kind: 'fold';
28
+ parentPath: UnixEntryPath;
29
+ entryNames: UnixEntryName[];
30
+ };
31
+ export declare const DisplayRow: {
32
+ equal(firstRow: DisplayRow, secondRow: DisplayRow): boolean;
25
33
  };
26
- export declare function rowsEqual(firstRow: DisplayRow, secondRow: DisplayRow): boolean;
27
- //# sourceMappingURL=display-row.d.ts.map
34
+ //# sourceMappingURL=display-row.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"display-row.d.ts","sourceRoot":"","sources":["../../src/domain/display-row.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;AAExC,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAErE;AAED,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;CAClB,GACD;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEN,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,CAStE;AAED,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,SAAS,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;CACrB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,SAAS,CAAC;IACtB,UAAU,EAAE,aAAa,EAAE,CAAC;CAC7B,CAAC;AAEN,wBAAgB,SAAS,CACvB,QAAQ,EAAE,UAAU,EACpB,SAAS,EAAE,UAAU,GACpB,OAAO,CAoBT"}
1
+ {"version":3,"file":"display-row.d.ts","sourceRoot":"","sources":["../../src/domain/display-row.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;CAClB,GACD;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEN,eAAO,MAAM,YAAY;yBACF,SAAS,GAAG,YAAY;CAU9C,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,aAAa,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC;CACrB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,aAAa,CAAC;IAC1B,UAAU,EAAE,aAAa,EAAE,CAAC;CAC7B,CAAC;AAEN,eAAO,MAAM,UAAU;oBACL,UAAU,aAAa,UAAU,GAAG,OAAO;CAqB5D,CAAC"}
@@ -1,27 +1,33 @@
1
+ import { UnixEntryPath } from './unix-entry.js';
1
2
  import { entryNamesEqual } from './unix-entry.js';
2
- export function pathsEqual(left, right) {
3
- return entryNamesEqual(left, right);
4
- }
5
- export function unixEntryToDisplayEntry(entry) {
3
+ export const DisplayEntry = {
4
+ fromUnixEntry(entry) {
6
5
  if (entry.kind === 'directory') {
7
- return {
8
- kind: 'directory',
9
- name: entry.name,
10
- };
6
+ return {
7
+ kind: 'directory',
8
+ name: entry.name,
9
+ };
11
10
  }
12
11
  return entry;
13
- }
14
- export function rowsEqual(firstRow, secondRow) {
12
+ },
13
+ };
14
+ export const DisplayRow = {
15
+ equal(firstRow, secondRow) {
15
16
  if (firstRow.kind !== secondRow.kind) {
16
- return false;
17
+ return false;
17
18
  }
18
19
  if (firstRow.kind === 'fold' && secondRow.kind === 'fold') {
19
- return (pathsEqual(firstRow.parentPath, secondRow.parentPath) &&
20
- entryNamesEqual(firstRow.entryNames, secondRow.entryNames));
20
+ return (
21
+ UnixEntryPath.equal(firstRow.parentPath, secondRow.parentPath) &&
22
+ entryNamesEqual(firstRow.entryNames, secondRow.entryNames)
23
+ );
21
24
  }
22
25
  if (firstRow.kind === 'entry' && secondRow.kind === 'entry') {
23
- return (pathsEqual(firstRow.parentPath, secondRow.parentPath) &&
24
- firstRow.entry.name === secondRow.entry.name);
26
+ return (
27
+ UnixEntryPath.equal(firstRow.parentPath, secondRow.parentPath) &&
28
+ firstRow.entry.name === secondRow.entry.name
29
+ );
25
30
  }
26
31
  return false;
27
- }
32
+ },
33
+ };
@@ -0,0 +1,48 @@
1
+ import { UnixEntry, UnixEntryPath } from './unix-entry.js';
2
+ import { InputState } from './input-state.js';
3
+ export type Effect =
4
+ | {
5
+ effectType: 'dispatchEffectAction';
6
+ action: EffectAction;
7
+ }
8
+ | {
9
+ effectType: 'loadDir';
10
+ path: UnixEntryPath;
11
+ }
12
+ | {
13
+ effectType: 'printFile';
14
+ path: UnixEntryPath;
15
+ }
16
+ | {
17
+ effectType: 'quit';
18
+ exitMessage: string;
19
+ }
20
+ | {
21
+ effectType: 'setInputState';
22
+ inputState: InputState;
23
+ };
24
+ export type EffectAction =
25
+ | {
26
+ effectActionType: 'nextEntry';
27
+ }
28
+ | {
29
+ effectActionType: 'prevEntry';
30
+ }
31
+ | {
32
+ effectActionType: 'updateDir';
33
+ path: UnixEntryPath;
34
+ entries: UnixEntry[] | undefined;
35
+ }
36
+ | {
37
+ effectActionType: 'outDir';
38
+ }
39
+ | {
40
+ effectActionType: 'fold';
41
+ }
42
+ | {
43
+ effectActionType: 'unfold';
44
+ }
45
+ | {
46
+ effectActionType: 'toggleFold';
47
+ };
48
+ //# sourceMappingURL=effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/domain/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,MAAM,MAAM,GACd;IACE,UAAU,EAAE,sBAAsB,CAAC;IACnC,MAAM,EAAE,YAAY,CAAC;CACtB,GACD;IACE,UAAU,EAAE,SAAS,CAAC;IACtB,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,UAAU,EAAE,WAAW,CAAC;IACxB,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,UAAU,EAAE,eAAe,CAAC;IAC5B,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAGN,MAAM,MAAM,YAAY,GACpB;IACE,gBAAgB,EAAE,WAAW,CAAC;CAC/B,GACD;IACE,gBAAgB,EAAE,WAAW,CAAC;CAC/B,GACD;IACE,gBAAgB,EAAE,WAAW,CAAC;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;CAClC,GACD;IACE,gBAAgB,EAAE,QAAQ,CAAC;CAC5B,GACD;IACE,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IACE,gBAAgB,EAAE,QAAQ,CAAC;CAC5B,GACD;IACE,gBAAgB,EAAE,YAAY,CAAC;CAChC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { UnixEntry, UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
+ export type FoldNode = {
3
+ children: Record<UnixEntryName, FoldNode>;
4
+ folds: UnixEntryName[];
5
+ };
6
+ export declare const FoldNode: {
7
+ getAtPath(rootNode: FoldNode, path: UnixEntryPath): FoldNode | undefined;
8
+ getIfEntryFolded(node: FoldNode | undefined, entry: UnixEntry): boolean;
9
+ modifyAtPath(
10
+ rootNode: FoldNode,
11
+ path: UnixEntryName[],
12
+ modifier: (targetNode: FoldNode) => FoldNode,
13
+ ): FoldNode;
14
+ addFoldedEntry(node: FoldNode, entry: UnixEntry): FoldNode;
15
+ addFoldedEntryAtPath(
16
+ rootNode: FoldNode,
17
+ path: UnixEntryName[],
18
+ entry: UnixEntry,
19
+ ): FoldNode;
20
+ createEmpty(): FoldNode;
21
+ setFoldedEntries(node: FoldNode, entries: UnixEntry[]): FoldNode;
22
+ removeFoldedEntry(node: FoldNode, entry: UnixEntry): FoldNode;
23
+ clearFoldedEntries(node: FoldNode): FoldNode;
24
+ };
25
+ //# sourceMappingURL=fold-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold-node.d.ts","sourceRoot":"","sources":["../../src/domain/fold-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAC1C,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,QAAQ;wBAEC,QAAQ,QAAQ,aAAa,GAAG,QAAQ,GAAG,SAAS;2BAgBjD,QAAQ,GAAG,SAAS,SAAS,SAAS,GAAG,OAAO;2BAM3D,QAAQ,QACZ,aAAa,EAAE,YACX,CAAC,UAAU,EAAE,QAAQ,KAAK,QAAQ,GAC3C,QAAQ;yBAwBU,QAAQ,SAAS,SAAS,GAAG,QAAQ;mCAU9C,QAAQ,QACZ,aAAa,EAAE,SACd,SAAS,GACf,QAAQ;mBAMI,QAAQ;2BAOA,QAAQ,WAAW,SAAS,EAAE,GAAG,QAAQ;4BAOxC,QAAQ,SAAS,SAAS,GAAG,QAAQ;6BAWpC,QAAQ,GAAG,QAAQ;CAO7C,CAAC"}
@@ -0,0 +1,93 @@
1
+ export const FoldNode = {
2
+ // Query-Like
3
+ getAtPath(rootNode, path) {
4
+ const [currentName, ...remainingPath] = path;
5
+ if (currentName === undefined) {
6
+ return rootNode;
7
+ }
8
+ const childNode = rootNode.children[currentName];
9
+ if (childNode === undefined) {
10
+ return undefined;
11
+ }
12
+ return FoldNode.getAtPath(childNode, remainingPath);
13
+ },
14
+ getIfEntryFolded(node, entry) {
15
+ return node !== undefined && hasFoldedEntryNamed(node, entry.name);
16
+ },
17
+ // Command/Modifer-Like
18
+ modifyAtPath(rootNode, path, modifier) {
19
+ const [currentName, ...remainingPath] = path;
20
+ // Base case
21
+ if (currentName === undefined) {
22
+ return modifier(rootNode);
23
+ }
24
+ // Create childNode to create path in tree to the needed node
25
+ const childNode = rootNode.children[currentName] ?? FoldNode.createEmpty();
26
+ return {
27
+ ...rootNode,
28
+ children: {
29
+ ...rootNode.children,
30
+ [currentName]: FoldNode.modifyAtPath(
31
+ childNode,
32
+ remainingPath,
33
+ modifier,
34
+ ),
35
+ },
36
+ };
37
+ },
38
+ addFoldedEntry(node, entry) {
39
+ // Avoid duplicates
40
+ if (hasFoldedEntryNamed(node, entry.name)) {
41
+ return node;
42
+ }
43
+ return setFoldedEntriesNamed(node, [...node.folds, entry.name]);
44
+ },
45
+ addFoldedEntryAtPath(rootNode, path, entry) {
46
+ return FoldNode.modifyAtPath(rootNode, path, (node) =>
47
+ FoldNode.addFoldedEntry(node, entry),
48
+ );
49
+ },
50
+ createEmpty() {
51
+ return {
52
+ children: Object.create(null),
53
+ folds: [],
54
+ };
55
+ },
56
+ setFoldedEntries(node, entries) {
57
+ return setFoldedEntriesNamed(
58
+ node,
59
+ entries.map((entry) => entry.name),
60
+ );
61
+ },
62
+ removeFoldedEntry(node, entry) {
63
+ if (!hasFoldedEntryNamed(node, entry.name)) {
64
+ return node;
65
+ }
66
+ return setFoldedEntriesNamed(
67
+ node,
68
+ node.folds.filter((entryName) => entryName !== entry.name),
69
+ );
70
+ },
71
+ clearFoldedEntries(node) {
72
+ if (node.folds.length === 0) {
73
+ return node;
74
+ }
75
+ return setFoldedEntriesNamed(node, []);
76
+ },
77
+ };
78
+ // PRIVATE HELPERS
79
+ // Queries
80
+ function hasFoldedEntryNamed(node, entryName) {
81
+ return node.folds.includes(entryName);
82
+ }
83
+ function uniqueEntryNames(entryNames) {
84
+ return [...new Set(entryNames)];
85
+ }
86
+ // Adding
87
+ function setFoldedEntriesNamed(node, entryNames) {
88
+ const uniqueNames = uniqueEntryNames(entryNames);
89
+ return {
90
+ ...node,
91
+ folds: uniqueNames,
92
+ };
93
+ }
@@ -0,0 +1,10 @@
1
+ export type InputState =
2
+ | {
3
+ inputMode: 'normal';
4
+ normalBuffer: string;
5
+ }
6
+ | {
7
+ inputMode: 'command';
8
+ commandLine: string;
9
+ };
10
+ //# sourceMappingURL=input-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-state.d.ts","sourceRoot":"","sources":["../../src/domain/input-state.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB;IACE,SAAS,EAAE,QAAQ,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,GACD;IACE,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ export type Intent = NormalModeIntent | CommandLineIntent;
2
+ export type NormalModeIntent =
3
+ | {
4
+ intentType: 'normalRight';
5
+ }
6
+ | {
7
+ intentType: 'normalLeft';
8
+ }
9
+ | {
10
+ intentType: 'normalDown';
11
+ }
12
+ | {
13
+ intentType: 'normalUp';
14
+ }
15
+ | {
16
+ intentType: 'setNormalBuffer';
17
+ normalBuffer: string;
18
+ };
19
+ export type CommandLineIntent =
20
+ | {
21
+ intentType: 'enterCommandLineMode';
22
+ }
23
+ | {
24
+ intentType: 'setCommandLine';
25
+ commandLine: string;
26
+ }
27
+ | {
28
+ intentType: 'executeCommandLine';
29
+ commandLine: string;
30
+ }
31
+ | {
32
+ intentType: 'exitCommandLineMode';
33
+ };
34
+ //# sourceMappingURL=intent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../src/domain/intent.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAE1D,MAAM,MAAM,gBAAgB,GACxB;IACE,UAAU,EAAE,aAAa,CAAC;CAC3B,GACD;IACE,UAAU,EAAE,YAAY,CAAC;CAC1B,GACD;IACE,UAAU,EAAE,YAAY,CAAC;CAC1B,GACD;IACE,UAAU,EAAE,UAAU,CAAC;CACxB,GACD;IACE,UAAU,EAAE,iBAAiB,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,iBAAiB,GACzB;IACE,UAAU,EAAE,sBAAsB,CAAC;CACpC,GACD;IACE,UAAU,EAAE,gBAAgB,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,UAAU,EAAE,oBAAoB,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,UAAU,EAAE,qBAAqB,CAAC;CACnC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import { UnixEntry, UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
+ import { UnixPath } from './unix-path.js';
3
+ import { FoldNode } from './fold-node.js';
4
+ import { Cursor } from './cursor.js';
5
+ export type NavigationEntry =
6
+ | {
7
+ kind: 'file';
8
+ name: UnixEntryName;
9
+ }
10
+ | {
11
+ kind: 'symlink';
12
+ name: UnixEntryName;
13
+ target: UnixPath;
14
+ }
15
+ | {
16
+ /**
17
+ * Undefined node means the directory has not been loaded.
18
+ */
19
+ kind: 'directory';
20
+ name: UnixEntryName;
21
+ node?: NavigationNode;
22
+ };
23
+ /**
24
+ * A directory as navigated: list of visible entries and folded entries.
25
+ */
26
+ export type NavigationNode = {
27
+ /**
28
+ * Currently visible entries.
29
+ */
30
+ entries: NavigationEntry[];
31
+ /**
32
+ * Currently loaded entries hidden by this directory's fold.
33
+ */
34
+ foldedEntries: NavigationEntry[];
35
+ };
36
+ export declare const NavigationNode: {
37
+ from(
38
+ entries: UnixEntry[] | undefined,
39
+ foldNode: FoldNode | undefined,
40
+ ): NavigationNode;
41
+ getNodeAtPath(
42
+ navigation: NavigationNode,
43
+ path: UnixEntryPath,
44
+ ): NavigationNode | undefined;
45
+ getEntryAtPath(
46
+ navigation: NavigationNode,
47
+ path: UnixEntryPath,
48
+ ): NavigationEntry | undefined;
49
+ nextCursor(rootNode: NavigationNode, cursor: Cursor): Cursor | undefined;
50
+ previousCursor(rootNode: NavigationNode, cursor: Cursor): Cursor | undefined;
51
+ cursorAfterFold(rootNode: NavigationNode, cursor: Cursor): Cursor | undefined;
52
+ parentCursor(navigation: NavigationNode, cursor: Cursor): Cursor | undefined;
53
+ visibleFilesPaths(
54
+ navigation: NavigationNode,
55
+ parentPath?: UnixEntryPath,
56
+ ): UnixEntryPath[];
57
+ };
58
+ //# sourceMappingURL=navigation-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation-node.d.ts","sourceRoot":"","sources":["../../src/domain/navigation-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;CAClB,GACD;IACE;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,OAAO,EAAE,eAAe,EAAE,CAAC;IAE3B;;OAEG;IACH,aAAa,EAAE,eAAe,EAAE,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,cAAc;kBAEd,SAAS,EAAE,GAAG,SAAS,YACtB,QAAQ,GAAG,SAAS,GAC7B,cAAc;8BA4DH,cAAc,QACpB,aAAa,GAClB,cAAc,GAAG,SAAS;+BAyBf,cAAc,QACpB,aAAa,GAClB,eAAe,GAAG,SAAS;yBA0BT,cAAc,UAAU,MAAM,GAAG,MAAM,GAAG,SAAS;6BAc/C,cAAc,UAAU,MAAM,GAAG,MAAM,GAAG,SAAS;8BAehE,cAAc,UAChB,MAAM,GACb,MAAM,GAAG,SAAS;6BAsCI,cAAc,UAAU,MAAM,GAAG,MAAM,GAAG,SAAS;kCA6B9D,cAAc,eACd,aAAa,GACxB,aAAa,EAAE;CA2BnB,CAAC"}