dirvi-lib 0.3.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 (61) 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 +15 -13
  17. package/dist/domain/cursor.js +43 -41
  18. package/dist/domain/display-row.d.ts +28 -23
  19. package/dist/domain/display-row.d.ts.map +1 -1
  20. package/dist/domain/display-row.js +26 -22
  21. package/dist/domain/effect.d.ts +48 -0
  22. package/dist/domain/effect.d.ts.map +1 -0
  23. package/dist/domain/effect.js +1 -0
  24. package/dist/domain/fold-node.d.ts +20 -12
  25. package/dist/domain/fold-node.js +82 -70
  26. package/dist/domain/input-state.d.ts +10 -0
  27. package/dist/domain/input-state.d.ts.map +1 -0
  28. package/dist/domain/input-state.js +1 -0
  29. package/dist/domain/intent.d.ts +34 -0
  30. package/dist/domain/intent.d.ts.map +1 -0
  31. package/dist/domain/intent.js +1 -0
  32. package/dist/domain/navigation-node.d.ts +47 -32
  33. package/dist/domain/navigation-node.js +201 -189
  34. package/dist/domain/state.d.ts +5 -5
  35. package/dist/domain/state.d.ts.map +1 -1
  36. package/dist/domain/state.js +7 -7
  37. package/dist/domain/unix-entry.d.ts +35 -19
  38. package/dist/domain/unix-entry.d.ts.map +1 -1
  39. package/dist/domain/unix-entry.js +94 -82
  40. package/dist/domain/unix-path.d.ts +1 -1
  41. package/dist/domain/unix-path.js +9 -6
  42. package/dist/domain/user-input.d.ts +27 -0
  43. package/dist/domain/user-input.d.ts.map +1 -0
  44. package/dist/domain/user-input.js +1 -0
  45. package/dist/index.d.ts +6 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +5 -0
  48. package/dist/infrastructure/get-cwd.d.ts +1 -1
  49. package/dist/infrastructure/get-cwd.js +12 -10
  50. package/dist/infrastructure/get-dir-lazy-entries.d.ts +4 -2
  51. package/dist/infrastructure/get-dir-lazy-entries.js +34 -28
  52. package/package.json +4 -2
  53. package/dist/domain/fold.d.ts +0 -10
  54. package/dist/domain/fold.d.ts.map +0 -1
  55. package/dist/domain/fold.js +0 -24
  56. package/dist/domain/navigation-entry.d.ts +0 -23
  57. package/dist/domain/navigation-entry.d.ts.map +0 -1
  58. package/dist/domain/navigation-entry.js +0 -52
  59. package/dist/domain/view.d.ts +0 -15
  60. package/dist/domain/view.d.ts.map +0 -1
  61. package/dist/domain/view.js +0 -12
@@ -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
+ });
@@ -1,17 +1,19 @@
1
1
  import { UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
2
  import { DisplayRow } from './display-row.js';
3
- export type Cursor = {
4
- kind: 'entry';
5
- parentPath: UnixEntryPath;
6
- entryName: UnixEntryName;
7
- } | {
8
- kind: 'fold';
9
- parentPath: UnixEntryPath;
10
- };
3
+ export type Cursor =
4
+ | {
5
+ kind: 'entry';
6
+ parentPath: UnixEntryPath;
7
+ entryName: UnixEntryName;
8
+ }
9
+ | {
10
+ kind: 'fold';
11
+ parentPath: UnixEntryPath;
12
+ };
11
13
  export declare const Cursor: {
12
- equal(left: Cursor, right: Cursor): boolean;
13
- matchesDisplayRow(cursor: Cursor, row: DisplayRow): boolean;
14
- fromDisplayRow(row: DisplayRow): Cursor;
15
- getPath(cursor: Cursor): UnixEntryPath | undefined;
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;
16
18
  };
17
- //# sourceMappingURL=cursor.d.ts.map
19
+ //# sourceMappingURL=cursor.d.ts.map
@@ -1,44 +1,46 @@
1
1
  import { UnixEntryPath } from './unix-entry.js';
2
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 (UnixEntryPath.equal(cursor.parentPath, row.parentPath) &&
18
- cursor.entryName === row.entry.name);
19
- }
20
- if (cursor.kind === 'fold' && row.kind === 'fold') {
21
- return UnixEntryPath.equal(cursor.parentPath, row.parentPath);
22
- }
23
- return false;
24
- },
25
- fromDisplayRow(row) {
26
- if (row.kind === 'entry') {
27
- return {
28
- kind: 'entry',
29
- parentPath: row.parentPath,
30
- entryName: row.entry.name,
31
- };
32
- }
33
- return {
34
- kind: 'fold',
35
- parentPath: row.parentPath,
36
- };
37
- },
38
- getPath(cursor) {
39
- if (cursor.kind === 'fold') {
40
- return undefined;
41
- }
42
- return [...cursor.parentPath, cursor.entryName];
43
- },
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
+ },
44
46
  };
@@ -1,29 +1,34 @@
1
1
  import { UnixEntry, UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
2
  import type { UnixPath } from './unix-path.js';
3
- export type DisplayEntry = {
4
- kind: 'file';
5
- name: UnixEntryName;
6
- } | {
7
- kind: 'symlink';
8
- name: UnixEntryName;
9
- target: UnixPath;
10
- } | {
11
- kind: 'directory';
12
- name: UnixEntryName;
13
- };
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
+ };
14
17
  export declare const DisplayEntry: {
15
- fromUnixEntry(entry: UnixEntry): DisplayEntry;
16
- };
17
- export type DisplayRow = {
18
- kind: 'entry';
19
- parentPath: UnixEntryPath;
20
- entry: DisplayEntry;
21
- } | {
22
- kind: 'fold';
23
- parentPath: UnixEntryPath;
24
- entryNames: UnixEntryName[];
18
+ fromUnixEntry(entry: UnixEntry): DisplayEntry;
25
19
  };
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
+ };
26
31
  export declare const DisplayRow: {
27
- equal(firstRow: DisplayRow, secondRow: DisplayRow): boolean;
32
+ equal(firstRow: DisplayRow, secondRow: DisplayRow): boolean;
28
33
  };
29
- //# 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,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,CAAA;AAED,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
+ {"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,29 +1,33 @@
1
1
  import { UnixEntryPath } from './unix-entry.js';
2
2
  import { entryNamesEqual } from './unix-entry.js';
3
3
  export const DisplayEntry = {
4
- fromUnixEntry(entry) {
5
- if (entry.kind === 'directory') {
6
- return {
7
- kind: 'directory',
8
- name: entry.name,
9
- };
10
- }
11
- return entry;
4
+ fromUnixEntry(entry) {
5
+ if (entry.kind === 'directory') {
6
+ return {
7
+ kind: 'directory',
8
+ name: entry.name,
9
+ };
12
10
  }
11
+ return entry;
12
+ },
13
13
  };
14
14
  export const DisplayRow = {
15
- equal(firstRow, secondRow) {
16
- if (firstRow.kind !== secondRow.kind) {
17
- return false;
18
- }
19
- if (firstRow.kind === 'fold' && secondRow.kind === 'fold') {
20
- return (UnixEntryPath.equal(firstRow.parentPath, secondRow.parentPath) &&
21
- entryNamesEqual(firstRow.entryNames, secondRow.entryNames));
22
- }
23
- if (firstRow.kind === 'entry' && secondRow.kind === 'entry') {
24
- return (UnixEntryPath.equal(firstRow.parentPath, secondRow.parentPath) &&
25
- firstRow.entry.name === secondRow.entry.name);
26
- }
27
- return false;
28
- },
15
+ equal(firstRow, secondRow) {
16
+ if (firstRow.kind !== secondRow.kind) {
17
+ return false;
18
+ }
19
+ if (firstRow.kind === 'fold' && secondRow.kind === 'fold') {
20
+ return (
21
+ UnixEntryPath.equal(firstRow.parentPath, secondRow.parentPath) &&
22
+ entryNamesEqual(firstRow.entryNames, secondRow.entryNames)
23
+ );
24
+ }
25
+ if (firstRow.kind === 'entry' && secondRow.kind === 'entry') {
26
+ return (
27
+ UnixEntryPath.equal(firstRow.parentPath, secondRow.parentPath) &&
28
+ firstRow.entry.name === secondRow.entry.name
29
+ );
30
+ }
31
+ return false;
32
+ },
29
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 {};
@@ -1,17 +1,25 @@
1
1
  import { UnixEntry, UnixEntryName, UnixEntryPath } from './unix-entry.js';
2
2
  export type FoldNode = {
3
- children: Record<UnixEntryName, FoldNode>;
4
- folds: UnixEntryName[];
3
+ children: Record<UnixEntryName, FoldNode>;
4
+ folds: UnixEntryName[];
5
5
  };
6
6
  export declare const FoldNode: {
7
- getAtPath(rootNode: FoldNode, path: UnixEntryPath): FoldNode | undefined;
8
- getIfEntryFolded(node: FoldNode | undefined, entry: UnixEntry): boolean;
9
- modifyAtPath(rootNode: FoldNode, path: UnixEntryName[], modifier: (targetNode: FoldNode) => FoldNode): FoldNode;
10
- addFoldedEntry(node: FoldNode, entry: UnixEntry): FoldNode;
11
- addFoldedEntryAtPath(rootNode: FoldNode, path: UnixEntryName[], entry: UnixEntry): FoldNode;
12
- createEmpty(): FoldNode;
13
- setFoldedEntries(node: FoldNode, entries: UnixEntry[]): FoldNode;
14
- removeFoldedEntry(node: FoldNode, entry: UnixEntry): FoldNode;
15
- clearFoldedEntries(node: FoldNode): 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;
16
24
  };
17
- //# sourceMappingURL=fold-node.d.ts.map
25
+ //# sourceMappingURL=fold-node.d.ts.map
@@ -1,81 +1,93 @@
1
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(childNode, remainingPath, modifier),
31
- },
32
- };
33
- },
34
- addFoldedEntry(node, entry) {
35
- // Avoid duplicates
36
- if (hasFoldedEntryNamed(node, entry.name)) {
37
- return node;
38
- }
39
- return setFoldedEntriesNamed(node, [...node.folds, entry.name]);
40
- },
41
- addFoldedEntryAtPath(rootNode, path, entry) {
42
- return FoldNode.modifyAtPath(rootNode, path, (node) => FoldNode.addFoldedEntry(node, entry));
43
- },
44
- createEmpty() {
45
- return {
46
- children: Object.create(null),
47
- folds: [],
48
- };
49
- },
50
- setFoldedEntries(node, entries) {
51
- return setFoldedEntriesNamed(node, entries.map((entry) => entry.name));
52
- },
53
- removeFoldedEntry(node, entry) {
54
- if (!hasFoldedEntryNamed(node, entry.name)) {
55
- return node;
56
- }
57
- return setFoldedEntriesNamed(node, node.folds.filter((entryName) => entryName !== entry.name));
58
- },
59
- clearFoldedEntries(node) {
60
- if (node.folds.length === 0) {
61
- return node;
62
- }
63
- return setFoldedEntriesNamed(node, []);
64
- },
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
+ },
65
77
  };
66
78
  // PRIVATE HELPERS
67
79
  // Queries
68
80
  function hasFoldedEntryNamed(node, entryName) {
69
- return node.folds.includes(entryName);
81
+ return node.folds.includes(entryName);
70
82
  }
71
83
  function uniqueEntryNames(entryNames) {
72
- return [...new Set(entryNames)];
84
+ return [...new Set(entryNames)];
73
85
  }
74
86
  // Adding
75
87
  function setFoldedEntriesNamed(node, entryNames) {
76
- const uniqueNames = uniqueEntryNames(entryNames);
77
- return {
78
- ...node,
79
- folds: uniqueNames,
80
- };
88
+ const uniqueNames = uniqueEntryNames(entryNames);
89
+ return {
90
+ ...node,
91
+ folds: uniqueNames,
92
+ };
81
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 {};