@mak-98/dirvi-cli 0.2.1 → 0.3.1

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 (60) hide show
  1. package/dist/application/action.d.ts +19 -0
  2. package/dist/application/action.d.ts.map +1 -0
  3. package/dist/application/action.js +1 -0
  4. package/dist/application/display-rows.d.ts +3 -3
  5. package/dist/application/display-rows.d.ts.map +1 -1
  6. package/dist/application/display-rows.js +7 -7
  7. package/dist/application/effect-to-action.d.ts +5 -0
  8. package/dist/application/effect-to-action.d.ts.map +1 -0
  9. package/dist/application/effect-to-action.js +79 -0
  10. package/dist/application/fold-helpers.d.ts +2 -2
  11. package/dist/application/fold-helpers.d.ts.map +1 -1
  12. package/dist/application/fold-helpers.js +0 -17
  13. package/dist/application/intent-to-effect.d.ts +39 -0
  14. package/dist/application/intent-to-effect.d.ts.map +1 -0
  15. package/dist/application/intent-to-effect.js +118 -0
  16. package/dist/application/reducer-action.d.ts +19 -0
  17. package/dist/application/reducer-action.d.ts.map +1 -0
  18. package/dist/application/reducer-action.js +1 -0
  19. package/dist/application/reducer.d.ts +3 -28
  20. package/dist/application/reducer.d.ts.map +1 -1
  21. package/dist/application/reducer.js +16 -172
  22. package/dist/application/user-input-to-intent.d.ts +15 -0
  23. package/dist/application/user-input-to-intent.d.ts.map +1 -0
  24. package/dist/application/user-input-to-intent.js +56 -0
  25. package/dist/domain/event-message.d.ts +3 -3
  26. package/dist/domain/event-message.d.ts.map +1 -1
  27. package/dist/index.js +2 -2
  28. package/dist/infrastructure/input.d.ts +3 -3
  29. package/dist/infrastructure/input.d.ts.map +1 -1
  30. package/dist/infrastructure/input.js +16 -7
  31. package/dist/infrastructure/load-initial-props.d.ts.map +1 -1
  32. package/dist/infrastructure/load-initial-props.js +6 -8
  33. package/dist/infrastructure/user-input.d.ts +17 -0
  34. package/dist/infrastructure/user-input.d.ts.map +1 -0
  35. package/dist/infrastructure/user-input.js +35 -0
  36. package/dist/ui/App.d.ts +4 -5
  37. package/dist/ui/App.d.ts.map +1 -1
  38. package/dist/ui/App.js +54 -58
  39. package/dist/ui/App2.d.ts +11 -0
  40. package/dist/ui/App2.d.ts.map +1 -0
  41. package/dist/ui/App2.js +96 -0
  42. package/dist/ui/AppShell.d.ts +3 -3
  43. package/dist/ui/AppShell.d.ts.map +1 -1
  44. package/dist/ui/AppShell.js +3 -3
  45. package/dist/ui/components/DirEntries.d.ts +2 -1
  46. package/dist/ui/components/DirEntries.d.ts.map +1 -1
  47. package/dist/ui/components/DirEntries.js +6 -7
  48. package/dist/ui/components/UnixEntryComponent.d.ts +6 -0
  49. package/dist/ui/components/UnixEntryComponent.d.ts.map +1 -0
  50. package/dist/ui/components/UnixEntryComponent.js +12 -0
  51. package/dist/ui/components/ViewRowComponent.d.ts +5 -0
  52. package/dist/ui/components/ViewRowComponent.d.ts.map +1 -0
  53. package/dist/ui/components/ViewRowComponent.js +13 -0
  54. package/dist/ui/hooks/useView.d.ts +4 -0
  55. package/dist/ui/hooks/useView.d.ts.map +1 -0
  56. package/dist/ui/hooks/useView.js +30 -0
  57. package/dist/ui/view.d.ts +18 -0
  58. package/dist/ui/view.d.ts.map +1 -0
  59. package/dist/ui/view.js +74 -0
  60. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnixEntryComponent.d.ts","sourceRoot":"","sources":["../../../src/ui/components/UnixEntryComponent.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB,+BAmBA"}
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Text } from 'ink';
3
+ export function UnixEntryComponent({ entry, selected, }) {
4
+ switch (entry.kind) {
5
+ case 'file':
6
+ return _jsx(Text, { inverse: selected, children: entry.name });
7
+ case 'symlink':
8
+ return (_jsxs(Text, { inverse: selected, children: [entry.name, " -> ", entry.target] }));
9
+ case 'directory':
10
+ return (_jsxs(Text, { inverse: selected, color: "blue", children: [entry.name, "/"] }));
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ import { ViewRow } from '../view.js';
2
+ export declare function ViewRowComponent({ row }: {
3
+ row: ViewRow;
4
+ }): import("react").JSX.Element;
5
+ //# sourceMappingURL=ViewRowComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ViewRowComponent.d.ts","sourceRoot":"","sources":["../../../src/ui/components/ViewRowComponent.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,+BAkCzD"}
@@ -0,0 +1,13 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ export function ViewRowComponent({ row }) {
4
+ const prefix = '';
5
+ switch (row.type) {
6
+ case 'file':
7
+ return (_jsx(Box, { paddingLeft: row.indent * 2, children: _jsxs(Text, { inverse: row.selected, children: [prefix, row.content] }) }));
8
+ case 'directory':
9
+ return (_jsx(Box, { paddingLeft: row.indent * 2, children: _jsxs(Text, { inverse: row.selected, color: "blue", children: [prefix, row.content] }) }));
10
+ case 'fold':
11
+ return (_jsx(Box, { paddingLeft: row.indent * 2, children: _jsxs(Text, { inverse: row.selected, dimColor: true, children: [prefix, row.content] }) }));
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ import { NavigationNode, State } from 'dirvi-lib';
2
+ import { View } from '../view.js';
3
+ export declare function useView(navigation: NavigationNode, state: State): View;
4
+ //# sourceMappingURL=useView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useView.d.ts","sourceRoot":"","sources":["../../../src/ui/hooks/useView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,cAAc,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,IAAI,EAAW,MAAM,YAAY,CAAC;AAO3C,wBAAgB,OAAO,CAAC,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAmBtE"}
@@ -0,0 +1,30 @@
1
+ import { View } from '../view.js';
2
+ import { useWindowSize } from 'ink';
3
+ import { useRef } from 'react';
4
+ // Hooks that keeps Ref of the viewport's start, and returns View sliced to
5
+ // only the rows that should be visible.
6
+ export function useView(navigation, state) {
7
+ const { rows: terminalRows } = useWindowSize();
8
+ const viewportStartRef = useRef(0);
9
+ const viewportHeight = Math.max(1, terminalRows);
10
+ const rows = View.createRows(navigation, state.cursor);
11
+ viewportStartRef.current = viewportStart(rows, viewportHeight, viewportStartRef.current);
12
+ return View.create(navigation, state.cursor, viewportHeight, viewportStartRef.current);
13
+ }
14
+ function viewportStart(rows, viewportHeight, currentViewportStart) {
15
+ const scrollMargin = 3;
16
+ const cursorIndex = rows.findIndex((row) => row.cursor);
17
+ const maximumViewportStart = Math.max(0, rows.length - viewportHeight);
18
+ let viewportStart = currentViewportStart;
19
+ if (cursorIndex >= 0) {
20
+ const firstVisibleCursorIndex = viewportStart + scrollMargin;
21
+ const lastVisibleCursorIndex = viewportStart + viewportHeight - 1 - scrollMargin;
22
+ if (cursorIndex < firstVisibleCursorIndex) {
23
+ viewportStart = cursorIndex - scrollMargin;
24
+ }
25
+ else if (cursorIndex > lastVisibleCursorIndex) {
26
+ viewportStart = cursorIndex - viewportHeight + 1 + scrollMargin;
27
+ }
28
+ }
29
+ return Math.max(0, Math.min(viewportStart, maximumViewportStart));
30
+ }
@@ -0,0 +1,18 @@
1
+ import { Cursor, NavigationNode } from 'dirvi-lib';
2
+ export type ViewRowType = 'file' | 'directory' | 'fold';
3
+ export type ViewRow = {
4
+ id: string;
5
+ indent: number;
6
+ selected: boolean;
7
+ cursor: boolean;
8
+ content: string;
9
+ type: ViewRowType;
10
+ };
11
+ export type View = {
12
+ rows: ViewRow[];
13
+ };
14
+ export declare const View: {
15
+ createRows(navigation: NavigationNode, cursor: Cursor): ViewRow[];
16
+ create(navigation: NavigationNode, cursor: Cursor, viewportHeight: number, viewportStart: number): View;
17
+ };
18
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/ui/view.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAEN,cAAc,EAEf,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAMxD,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,IAAI;2BAED,cAAc,UAClB,MAAM,GACb,OAAO,EAAE;uBAKE,cAAc,UAClB,MAAM,kBACE,MAAM,iBACP,MAAM,GACpB,IAAI;CAUR,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { UnixEntryPath, } from 'dirvi-lib';
2
+ export const View = {
3
+ createRows(navigation, cursor) {
4
+ return viewRowsAtNode(navigation, [], cursor);
5
+ },
6
+ create(navigation, cursor, viewportHeight, viewportStart) {
7
+ const rows = View.createRows(navigation, cursor);
8
+ return {
9
+ rows: rows.slice(viewportStart, viewportStart + viewportHeight),
10
+ };
11
+ },
12
+ };
13
+ function viewRowsAtNode(node, parentPath, cursor) {
14
+ const rows = [];
15
+ for (const entry of node.entries) {
16
+ const isCursor = cursor.kind === 'entry' &&
17
+ UnixEntryPath.equal(cursor.parentPath, parentPath) &&
18
+ cursor.entryName === entry.name;
19
+ rows.push(viewRowForEntry(entry, parentPath, isCursor));
20
+ if (entry.kind !== 'directory' || entry.node === undefined) {
21
+ continue;
22
+ }
23
+ rows.push(...viewRowsAtNode(entry.node, [...parentPath, entry.name], cursor));
24
+ }
25
+ if (node.foldedEntries.length > 0) {
26
+ const isCursor = cursor.kind === 'fold' &&
27
+ UnixEntryPath.equal(cursor.parentPath, parentPath);
28
+ rows.push({
29
+ id: foldId(parentPath),
30
+ indent: parentPath.length,
31
+ selected: isCursor,
32
+ cursor: isCursor,
33
+ content: `⋯ ${node.foldedEntries.length} folded entries`,
34
+ type: 'fold',
35
+ });
36
+ }
37
+ return rows;
38
+ }
39
+ function viewRowForEntry(entry, parentPath, cursor) {
40
+ return {
41
+ id: entryId(parentPath, entry.name),
42
+ indent: parentPath.length,
43
+ selected: cursor,
44
+ cursor,
45
+ content: content(entry),
46
+ type: type(entry),
47
+ };
48
+ }
49
+ function entryId(parentPath, entryName) {
50
+ return `entry:${JSON.stringify([...parentPath, entryName])}`;
51
+ }
52
+ function foldId(parentPath) {
53
+ return `fold:${JSON.stringify(parentPath)}`;
54
+ }
55
+ function content(entry) {
56
+ switch (entry.kind) {
57
+ case 'file':
58
+ return entry.name;
59
+ case 'directory':
60
+ return `${entry.name}/`;
61
+ case 'symlink':
62
+ return `${entry.name} -> ${entry.target}`;
63
+ }
64
+ }
65
+ function type(entry) {
66
+ switch (entry.kind) {
67
+ case 'file':
68
+ return 'file';
69
+ case 'directory':
70
+ return 'directory';
71
+ case 'symlink':
72
+ return 'file';
73
+ }
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mak-98/dirvi-cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "A Vim-inspired TUI for browsing directories.",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-or-later",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "dependencies": {
15
15
  "commander": "^13.0.0",
16
- "dirvi-lib": "0.2.0",
16
+ "dirvi-lib": "0.3.0",
17
17
  "ink": "^7.1.1",
18
18
  "react": "^19.0.0"
19
19
  },