epiq 0.0.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/dist/app.d.ts +5 -0
- package/dist/app.js +12 -0
- package/dist/board/actions/board-action-map.d.ts +11 -0
- package/dist/board/actions/board-action-map.js +11 -0
- package/dist/board/actions/move-actions-routes.d.ts +4 -0
- package/dist/board/actions/move-actions-routes.js +31 -0
- package/dist/board/actions/move-actions.d.ts +5 -0
- package/dist/board/actions/move-actions.js +49 -0
- package/dist/board/board-action-map.d.ts +9 -0
- package/dist/board/board-action-map.js +7 -0
- package/dist/board/components/Board.d.ts +6 -0
- package/dist/board/components/Board.js +19 -0
- package/dist/board/components/Help.d.ts +4 -0
- package/dist/board/components/Help.js +21 -0
- package/dist/board/components/Logo.d.ts +2 -0
- package/dist/board/components/Logo.js +21 -0
- package/dist/board/components/ScrollBox.d.ts +9 -0
- package/dist/board/components/ScrollBox.js +22 -0
- package/dist/board/components/Swimlane.d.ts +8 -0
- package/dist/board/components/Swimlane.js +10 -0
- package/dist/board/components/Swimlanes.d.ts +8 -0
- package/dist/board/components/Swimlanes.js +20 -0
- package/dist/board/components/TicketListItem.d.ts +6 -0
- package/dist/board/components/TicketListItem.js +12 -0
- package/dist/board/components/TicketUI.d.ts +8 -0
- package/dist/board/components/TicketUI.js +9 -0
- package/dist/board/mock/board.d.ts +2 -0
- package/dist/board/mock/board.js +474 -0
- package/dist/board/model/board.model.d.ts +26 -0
- package/dist/board/model/board.model.js +6 -0
- package/dist/board/move-actions-routes.d.ts +4 -0
- package/dist/board/move-actions-routes.js +31 -0
- package/dist/board/move-actions.d.ts +5 -0
- package/dist/board/move-actions.js +49 -0
- package/dist/board/render/color.d.ts +7 -0
- package/dist/board/render/color.js +21 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +57 -0
- package/dist/components/Board.d.ts +6 -0
- package/dist/components/Board.js +15 -0
- package/dist/components/Help.d.ts +4 -0
- package/dist/components/Help.js +21 -0
- package/dist/components/Swimlane.d.ts +8 -0
- package/dist/components/Swimlane.js +10 -0
- package/dist/components/TicketListItem.d.ts +6 -0
- package/dist/components/TicketListItem.js +12 -0
- package/dist/lib/actions/board-action-map.d.ts +9 -0
- package/dist/lib/actions/board-action-map.js +7 -0
- package/dist/lib/actions/move-actions-utils.d.ts +5 -0
- package/dist/lib/actions/move-actions-utils.js +43 -0
- package/dist/lib/actions/move-actions.d.ts +4 -0
- package/dist/lib/actions/move-actions.js +31 -0
- package/dist/lib/board/board-action-map.d.ts +9 -0
- package/dist/lib/board/board-action-map.js +7 -0
- package/dist/lib/board/move-actions-routes.d.ts +4 -0
- package/dist/lib/board/move-actions-routes.js +31 -0
- package/dist/lib/board/move-actions.d.ts +5 -0
- package/dist/lib/board/move-actions.js +43 -0
- package/dist/lib/board-utils.d.ts +7 -0
- package/dist/lib/board-utils.js +33 -0
- package/dist/lib/default-actions-routes.d.ts +4 -0
- package/dist/lib/default-actions-routes.js +47 -0
- package/dist/lib/default-actions.d.ts +4 -0
- package/dist/lib/default-actions.js +47 -0
- package/dist/lib/navigation-context.d.ts +16 -0
- package/dist/lib/navigation-context.js +1 -0
- package/dist/lib/navigation.d.ts +10 -0
- package/dist/lib/navigation.js +74 -0
- package/dist/lib/render-utils.d.ts +10 -0
- package/dist/lib/render-utils.js +12 -0
- package/dist/lib/state.d.ts +8 -0
- package/dist/lib/state.js +8 -0
- package/dist/lib/types/action-map.model.d.ts +14 -0
- package/dist/lib/types/action-map.model.js +4 -0
- package/dist/lib/types/board.model.d.ts +21 -0
- package/dist/lib/types/board.model.js +5 -0
- package/dist/lib/types/navigation.model.d.ts +9 -0
- package/dist/lib/types/navigation.model.js +1 -0
- package/dist/lib/utils/array-utils.d.ts +5 -0
- package/dist/lib/utils/array-utils.js +7 -0
- package/dist/lib/utils/default-action-utils.d.ts +7 -0
- package/dist/lib/utils/default-action-utils.js +50 -0
- package/dist/lib/utils/default-actions.d.ts +7 -0
- package/dist/lib/utils/default-actions.js +50 -0
- package/dist/lib/utils/key-intent.d.ts +16 -0
- package/dist/lib/utils/key-intent.js +65 -0
- package/dist/lib/utils.d.ts +10 -0
- package/dist/lib/utils.js +12 -0
- package/dist/mock/board.d.ts +2 -0
- package/dist/mock/board.js +139 -0
- package/dist/navigation/actions/default-actions-routes.d.ts +4 -0
- package/dist/navigation/actions/default-actions-routes.js +47 -0
- package/dist/navigation/actions/default-actions.d.ts +7 -0
- package/dist/navigation/actions/default-actions.js +48 -0
- package/dist/navigation/model/action-map.model.d.ts +14 -0
- package/dist/navigation/model/action-map.model.js +4 -0
- package/dist/navigation/model/navigation-ctx.model.d.ts +16 -0
- package/dist/navigation/model/navigation-ctx.model.js +2 -0
- package/dist/navigation/model/navigation-tree.model.d.ts +9 -0
- package/dist/navigation/model/navigation-tree.model.js +1 -0
- package/dist/navigation/navigation.d.ts +10 -0
- package/dist/navigation/navigation.js +74 -0
- package/dist/navigation/state/state.d.ts +11 -0
- package/dist/navigation/state/state.js +10 -0
- package/dist/navigation/utils/key-intent.d.ts +16 -0
- package/dist/navigation/utils/key-intent.js +65 -0
- package/package.json +57 -0
- package/readme.md +37 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { render } from 'ink';
|
|
3
|
+
import meow from 'meow';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import App from './app.js';
|
|
6
|
+
import { BoardActions } from './board/actions/board-action-map.js';
|
|
7
|
+
import { board } from './board/mock/board.js';
|
|
8
|
+
import { buildDefaultActions } from './navigation/actions/default-actions-routes.js';
|
|
9
|
+
import { navigate } from './navigation/navigation.js';
|
|
10
|
+
import { setState } from './navigation/state/state.js';
|
|
11
|
+
const cli = meow(`
|
|
12
|
+
Usage
|
|
13
|
+
$ epiq
|
|
14
|
+
|
|
15
|
+
Options
|
|
16
|
+
--name Your name
|
|
17
|
+
|
|
18
|
+
Examples
|
|
19
|
+
$ epiq --name=Jane
|
|
20
|
+
Hello, Jane
|
|
21
|
+
`, {
|
|
22
|
+
importMeta: import.meta,
|
|
23
|
+
flags: {
|
|
24
|
+
name: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
cli;
|
|
30
|
+
export const main = () => {
|
|
31
|
+
console.clear();
|
|
32
|
+
navigate({
|
|
33
|
+
index: 0,
|
|
34
|
+
breadCrumb: [board],
|
|
35
|
+
callbacks: {
|
|
36
|
+
render: () => {
|
|
37
|
+
render(React.createElement(App, { board: board }));
|
|
38
|
+
},
|
|
39
|
+
onSelectChange: (selected, breadCrumb) => {
|
|
40
|
+
if (!selected)
|
|
41
|
+
return;
|
|
42
|
+
const type = selected
|
|
43
|
+
.actionContext; // Fix so that we can infer this type
|
|
44
|
+
setState(state => ({
|
|
45
|
+
...state,
|
|
46
|
+
currentNode: selected,
|
|
47
|
+
breadCrumb,
|
|
48
|
+
availableActions: [...buildDefaultActions(), ...BoardActions[type]],
|
|
49
|
+
}));
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
main();
|
|
55
|
+
process.stdout.on('resize', () => {
|
|
56
|
+
render(React.createElement(App, { board: board }));
|
|
57
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Box, Text, useApp, useInput } from 'ink';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { SwimlaneUI } from './Swimlane.js';
|
|
4
|
+
export const BoardUI = ({ board, swimlaneWidth, }) => {
|
|
5
|
+
const { exit } = useApp();
|
|
6
|
+
useInput((input, key) => {
|
|
7
|
+
if (key.escape || input === 'q') {
|
|
8
|
+
exit();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return (React.createElement(Box, { flexDirection: "column" },
|
|
12
|
+
React.createElement(Text, null, board.name.toUpperCase()),
|
|
13
|
+
React.createElement(Box, { flexDirection: "row" },
|
|
14
|
+
React.createElement(SwimlaneUI, { items: board.children, width: swimlaneWidth }))));
|
|
15
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Box, Text } from 'ink';
|
|
2
|
+
import { navigationState } from '../lib/state.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export const HelpUI = ({ width }) => (React.createElement(Box, { flexDirection: "column", paddingLeft: 1, paddingRight: 1, borderColor: "gray", borderStyle: "round", width: width },
|
|
5
|
+
React.createElement(Box, null,
|
|
6
|
+
React.createElement(Text, { color: "gray" }, "Toggle help with \"H\"")),
|
|
7
|
+
navigationState.viewHelp
|
|
8
|
+
? navigationState.availableActions
|
|
9
|
+
.filter(action => Boolean(action.description))
|
|
10
|
+
.filter(x => x.mode === navigationState.mode)
|
|
11
|
+
.map((action, index) => {
|
|
12
|
+
const [leftRaw, rightRaw] = action.description.split(']');
|
|
13
|
+
const left = leftRaw?.replace('[', '');
|
|
14
|
+
const right = rightRaw?.trim(); // no extra space
|
|
15
|
+
return (React.createElement(Box, { paddingLeft: 1, key: index, flexDirection: "row" },
|
|
16
|
+
React.createElement(Box, { width: 20 },
|
|
17
|
+
React.createElement(Text, { color: "gray" }, right)),
|
|
18
|
+
React.createElement(Box, { flexGrow: 1 },
|
|
19
|
+
React.createElement(Text, { color: "gray" }, left))));
|
|
20
|
+
})
|
|
21
|
+
: null));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Box, Text } from 'ink';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TicketListItemUI } from './TicketListItem.js';
|
|
4
|
+
export const SwimlaneUI = ({ items, width }) => {
|
|
5
|
+
return (React.createElement(Box, { flexDirection: "row" }, items.map((lane, index) => (React.createElement(React.Fragment, { key: index },
|
|
6
|
+
React.createElement(Box, { flexDirection: "column", width: width, borderStyle: "round", borderColor: lane.isSelected ? 'green' : 'gray', paddingRight: 1, paddingLeft: 1, paddingBottom: 1, minHeight: 15 },
|
|
7
|
+
React.createElement(Box, { borderStyle: "round", borderColor: 'gray', justifyContent: "center" },
|
|
8
|
+
React.createElement(Text, { bold: true }, lane.name)),
|
|
9
|
+
lane.children.map((ticket, index) => (React.createElement(TicketListItemUI, { key: index, width: width, ticket: ticket })))))))));
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import { navigationState } from '../lib/state.js';
|
|
4
|
+
const truncateWithEllipsis = (str, width) => str.length >= width ? str.slice(0, width - 3) + '...' : str;
|
|
5
|
+
export const TicketListItemUI = ({ width, ticket: { name, id, isSelected }, }) => (React.createElement(Box, { borderBottom: true },
|
|
6
|
+
React.createElement(Text, { color: isSelected && navigationState.mode === 'move'
|
|
7
|
+
? 'white'
|
|
8
|
+
: isSelected
|
|
9
|
+
? 'green'
|
|
10
|
+
: navigationState.mode === 'move'
|
|
11
|
+
? 'gray'
|
|
12
|
+
: 'white' }, truncateWithEllipsis(id + ' - ' + name, width - 5))));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NavigateCtx } from '../navigation-context.js';
|
|
2
|
+
import { ActionMap } from '../types/action-map.model.js';
|
|
3
|
+
type BoardActionMap = ActionMap<{
|
|
4
|
+
BOARD: [NavigateCtx];
|
|
5
|
+
SWIMLANE: [NavigateCtx];
|
|
6
|
+
TICKET: [NavigateCtx];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const BoardActions: BoardActionMap;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BoardItemTypes } from '../types/board.model.js';
|
|
2
|
+
import { moveAcrossParents, moveWithinParent } from './move-actions.js';
|
|
3
|
+
export const BoardActions = {
|
|
4
|
+
[BoardItemTypes.BOARD]: [],
|
|
5
|
+
[BoardItemTypes.SWIMLANE]: [...moveWithinParent],
|
|
6
|
+
[BoardItemTypes.TICKET]: [...moveWithinParent, ...moveAcrossParents],
|
|
7
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NavigateCtx } from '../navigation-context.js';
|
|
2
|
+
export declare const moveChildToNextParent: (ctx: NavigateCtx) => void;
|
|
3
|
+
export declare const moveChildToPreviousParent: (ctx: NavigateCtx) => void;
|
|
4
|
+
export declare const moveChildPreviousWithinParent: (ctx: NavigateCtx) => void;
|
|
5
|
+
export declare const moveChildNextWithinParent: (ctx: NavigateCtx) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { moveItemInArray } from '../utils/array-utils.js';
|
|
2
|
+
function moveNodeToSiblingContainer(ctx, direction) {
|
|
3
|
+
const ancestors = ctx.breadCrumb;
|
|
4
|
+
const parent = ancestors.at(-1);
|
|
5
|
+
const grandParent = ancestors.at(-2);
|
|
6
|
+
if (!parent || !grandParent)
|
|
7
|
+
return;
|
|
8
|
+
const parentIndex = grandParent.children.findIndex(x => x.id === parent.id);
|
|
9
|
+
const targetIndex = parentIndex + direction;
|
|
10
|
+
if (parentIndex < 0 ||
|
|
11
|
+
targetIndex < 0 ||
|
|
12
|
+
targetIndex >= grandParent.children.length)
|
|
13
|
+
return;
|
|
14
|
+
const sibling = grandParent.children[targetIndex];
|
|
15
|
+
if (!sibling)
|
|
16
|
+
return;
|
|
17
|
+
if (!sibling?.children?.length && !Array.isArray(sibling.children))
|
|
18
|
+
return;
|
|
19
|
+
const currentIndex = ctx._selectedIndex;
|
|
20
|
+
if (currentIndex < 0 || currentIndex >= parent.children.length)
|
|
21
|
+
return;
|
|
22
|
+
const [node] = parent.children.splice(currentIndex, 1);
|
|
23
|
+
sibling.children.push(node);
|
|
24
|
+
const newBreadCrumb = [...ctx.breadCrumb.slice(0, -1), sibling];
|
|
25
|
+
const newIndex = sibling.children.length - 1;
|
|
26
|
+
ctx.reInvokeNavigate(newIndex, newBreadCrumb);
|
|
27
|
+
}
|
|
28
|
+
export const moveChildToNextParent = (ctx) => moveNodeToSiblingContainer(ctx, 1);
|
|
29
|
+
export const moveChildToPreviousParent = (ctx) => moveNodeToSiblingContainer(ctx, -1);
|
|
30
|
+
function moveChildWithinParent(ctx, direction) {
|
|
31
|
+
const from = ctx._selectedIndex;
|
|
32
|
+
const to = from + direction;
|
|
33
|
+
if (to < 0 || to >= ctx.navigationNode.children.length)
|
|
34
|
+
return;
|
|
35
|
+
moveItemInArray({
|
|
36
|
+
array: ctx.navigationNode.children,
|
|
37
|
+
from,
|
|
38
|
+
to,
|
|
39
|
+
});
|
|
40
|
+
ctx.select(to);
|
|
41
|
+
}
|
|
42
|
+
export const moveChildPreviousWithinParent = (ctx) => moveChildWithinParent(ctx, -1);
|
|
43
|
+
export const moveChildNextWithinParent = (ctx) => moveChildWithinParent(ctx, 1);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Mode } from '../types/action-map.model.js';
|
|
2
|
+
import { KeyIntent } from '../utils/key-intent.js';
|
|
3
|
+
import { moveChildNextWithinParent, moveChildPreviousWithinParent, moveChildToNextParent, moveChildToPreviousParent, } from './move-actions-utils.js';
|
|
4
|
+
export const moveWithinParent = [
|
|
5
|
+
{
|
|
6
|
+
mode: Mode.DEFAULT,
|
|
7
|
+
description: '[Shift + direction] Move item',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
intent: KeyIntent.MovePreviousItem,
|
|
11
|
+
mode: Mode.DEFAULT,
|
|
12
|
+
action: moveChildPreviousWithinParent,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
intent: KeyIntent.MoveNextItem,
|
|
16
|
+
mode: Mode.DEFAULT,
|
|
17
|
+
action: moveChildNextWithinParent,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
export const moveAcrossParents = [
|
|
21
|
+
{
|
|
22
|
+
intent: KeyIntent.MoveToNextContainer,
|
|
23
|
+
mode: Mode.DEFAULT,
|
|
24
|
+
action: moveChildToNextParent,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
intent: KeyIntent.MoveToPreviousContainer,
|
|
28
|
+
mode: Mode.DEFAULT,
|
|
29
|
+
action: moveChildToPreviousParent,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NavigateCtx } from '../navigation-context.js';
|
|
2
|
+
import { ActionMap } from '../types/action-map.model.js';
|
|
3
|
+
type BoardActionMap = ActionMap<{
|
|
4
|
+
BOARD: [NavigateCtx];
|
|
5
|
+
SWIMLANE: [NavigateCtx];
|
|
6
|
+
TICKET: [NavigateCtx];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const BoardActions: BoardActionMap;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BoardItemTypes } from '../types/board.model.js';
|
|
2
|
+
import { moveAcrossParents, moveWithinParent } from './move-actions-routes.js';
|
|
3
|
+
export const BoardActions = {
|
|
4
|
+
[BoardItemTypes.BOARD]: [],
|
|
5
|
+
[BoardItemTypes.SWIMLANE]: [...moveWithinParent],
|
|
6
|
+
[BoardItemTypes.TICKET]: [...moveWithinParent, ...moveAcrossParents],
|
|
7
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Mode } from '../types/action-map.model.js';
|
|
2
|
+
import { KeyIntent } from '../utils/key-intent.js';
|
|
3
|
+
import { moveChildNextWithinParent, moveChildPreviousWithinParent, moveChildToNextParent, moveChildToPreviousParent, } from './move-actions.js';
|
|
4
|
+
export const moveWithinParent = [
|
|
5
|
+
{
|
|
6
|
+
mode: Mode.DEFAULT,
|
|
7
|
+
description: '[Shift + direction] Move item',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
intent: KeyIntent.MovePreviousItem,
|
|
11
|
+
mode: Mode.DEFAULT,
|
|
12
|
+
action: moveChildPreviousWithinParent,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
intent: KeyIntent.MoveNextItem,
|
|
16
|
+
mode: Mode.DEFAULT,
|
|
17
|
+
action: moveChildNextWithinParent,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
export const moveAcrossParents = [
|
|
21
|
+
{
|
|
22
|
+
intent: KeyIntent.MoveToNextContainer,
|
|
23
|
+
mode: Mode.DEFAULT,
|
|
24
|
+
action: moveChildToNextParent,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
intent: KeyIntent.MoveToPreviousContainer,
|
|
28
|
+
mode: Mode.DEFAULT,
|
|
29
|
+
action: moveChildToPreviousParent,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NavigateCtx } from '../navigation-context.js';
|
|
2
|
+
export declare const moveChildToNextParent: (ctx: NavigateCtx) => void;
|
|
3
|
+
export declare const moveChildToPreviousParent: (ctx: NavigateCtx) => void;
|
|
4
|
+
export declare const moveChildPreviousWithinParent: (ctx: NavigateCtx) => void;
|
|
5
|
+
export declare const moveChildNextWithinParent: (ctx: NavigateCtx) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { moveItemInArray } from '../utils/array-utils.js';
|
|
2
|
+
function moveNodeToSiblingContainer(ctx, direction) {
|
|
3
|
+
const ancestors = ctx.breadCrumb;
|
|
4
|
+
const parent = ancestors.at(-1);
|
|
5
|
+
const grandParent = ancestors.at(-2);
|
|
6
|
+
if (!parent || !grandParent)
|
|
7
|
+
return;
|
|
8
|
+
const parentIndex = grandParent.children.findIndex(x => x.id === parent.id);
|
|
9
|
+
const targetIndex = parentIndex + direction;
|
|
10
|
+
if (parentIndex < 0 ||
|
|
11
|
+
targetIndex < 0 ||
|
|
12
|
+
targetIndex >= grandParent.children.length)
|
|
13
|
+
return;
|
|
14
|
+
const sibling = grandParent.children[targetIndex];
|
|
15
|
+
if (!sibling)
|
|
16
|
+
return;
|
|
17
|
+
if (!sibling?.children?.length && !Array.isArray(sibling.children))
|
|
18
|
+
return;
|
|
19
|
+
const currentIndex = ctx._selectedIndex;
|
|
20
|
+
if (currentIndex < 0 || currentIndex >= parent.children.length)
|
|
21
|
+
return;
|
|
22
|
+
const [node] = parent.children.splice(currentIndex, 1);
|
|
23
|
+
sibling.children.push(node);
|
|
24
|
+
const newBreadCrumb = [...ctx.breadCrumb.slice(0, -1), sibling];
|
|
25
|
+
const newIndex = sibling.children.length - 1;
|
|
26
|
+
ctx.reInvokeNavigate(newIndex, newBreadCrumb);
|
|
27
|
+
}
|
|
28
|
+
export const moveChildToNextParent = (ctx) => moveNodeToSiblingContainer(ctx, 1);
|
|
29
|
+
export const moveChildToPreviousParent = (ctx) => moveNodeToSiblingContainer(ctx, -1);
|
|
30
|
+
function moveChildWithinParent(ctx, direction) {
|
|
31
|
+
const from = ctx._selectedIndex;
|
|
32
|
+
const to = from + direction;
|
|
33
|
+
if (to < 0 || to >= ctx.navigationNode.children.length)
|
|
34
|
+
return;
|
|
35
|
+
moveItemInArray({
|
|
36
|
+
array: ctx.navigationNode.children,
|
|
37
|
+
from,
|
|
38
|
+
to,
|
|
39
|
+
});
|
|
40
|
+
ctx.select(to);
|
|
41
|
+
}
|
|
42
|
+
export const moveChildPreviousWithinParent = (ctx) => moveChildWithinParent(ctx, -1);
|
|
43
|
+
export const moveChildNextWithinParent = (ctx) => moveChildWithinParent(ctx, 1);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Swimlane, Ticket } from './types/board.model.js';
|
|
2
|
+
import { NavigationTree } from './types/navigation.model.js';
|
|
3
|
+
/**
|
|
4
|
+
* Move a ticket to a new swimlane.
|
|
5
|
+
*/
|
|
6
|
+
export declare function moveTicket(ticket: Ticket, destination: Swimlane): void;
|
|
7
|
+
export declare function findNodeById(tree: NavigationTree, id: string): NavigationTree | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { board } from '../mock/board.js';
|
|
2
|
+
/**
|
|
3
|
+
* Move a ticket to a new swimlane.
|
|
4
|
+
*/
|
|
5
|
+
export function moveTicket(ticket, destination) {
|
|
6
|
+
let realTicket;
|
|
7
|
+
// Step 1: Find and remove the real ticket from the current swimlane
|
|
8
|
+
for (const swimlane of board.children) {
|
|
9
|
+
const index = swimlane.children.findIndex(t => t.id === ticket.id);
|
|
10
|
+
if (index !== -1) {
|
|
11
|
+
realTicket = swimlane.children[index];
|
|
12
|
+
swimlane.children.splice(index, 1);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Step 2: Add it to the destination swimlane
|
|
17
|
+
if (realTicket && destination.actionContext === 'SWIMLANE') {
|
|
18
|
+
destination.children.push(realTicket);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.warn('Ticket not found or destination invalid. No move performed.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function findNodeById(tree, id) {
|
|
25
|
+
if (tree.id === id)
|
|
26
|
+
return tree;
|
|
27
|
+
for (const child of tree.children) {
|
|
28
|
+
const found = findNodeById(child, id);
|
|
29
|
+
if (found)
|
|
30
|
+
return found;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { setState } from './state.js';
|
|
2
|
+
import { Mode } from './types/action-map.model.js';
|
|
3
|
+
import { enterChildNode, exitToParentNode, navigateToNextContainer, navigateToNextItem, navigateToPreviousContainer, navigateToPreviousItem, } from './utils/default-actions.js';
|
|
4
|
+
import { KeyIntent } from './utils/key-intent.js';
|
|
5
|
+
export const buildDefaultActions = () => [
|
|
6
|
+
{
|
|
7
|
+
mode: Mode.DEFAULT,
|
|
8
|
+
description: '[ARROW KEYS] Navigate',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
intent: KeyIntent.ToggleHelp,
|
|
12
|
+
mode: Mode.DEFAULT,
|
|
13
|
+
action: () => setState(state => ({ ...state, viewHelp: !state.viewHelp })),
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
intent: KeyIntent.Confirm,
|
|
17
|
+
mode: Mode.DEFAULT,
|
|
18
|
+
description: '[ENTER] Confirm',
|
|
19
|
+
action: enterChildNode,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
intent: KeyIntent.Exit,
|
|
23
|
+
mode: Mode.DEFAULT,
|
|
24
|
+
description: '[E] Exit container',
|
|
25
|
+
action: exitToParentNode,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
intent: KeyIntent.NavPreviousItem,
|
|
29
|
+
mode: Mode.DEFAULT,
|
|
30
|
+
action: navigateToPreviousItem,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
intent: KeyIntent.NavNextItem,
|
|
34
|
+
mode: Mode.DEFAULT,
|
|
35
|
+
action: navigateToNextItem,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
intent: KeyIntent.NavToPreviousContainer,
|
|
39
|
+
mode: Mode.DEFAULT,
|
|
40
|
+
action: navigateToPreviousContainer,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
intent: KeyIntent.NavToNextContainer,
|
|
44
|
+
mode: Mode.DEFAULT,
|
|
45
|
+
action: navigateToNextContainer,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { setState } from './state.js';
|
|
2
|
+
import { Mode } from './types/action-map.model.js';
|
|
3
|
+
import { enterChildNode, exitToParentNode, navigateToNextContainer, navigateToNextItem, navigateToPreviousContainer, navigateToPreviousItem, } from './utils/default-action-utils.js';
|
|
4
|
+
import { KeyIntent } from './utils/key-intent.js';
|
|
5
|
+
export const buildDefaultActions = () => [
|
|
6
|
+
{
|
|
7
|
+
mode: Mode.DEFAULT,
|
|
8
|
+
description: '[ARROW KEYS] Navigate',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
intent: KeyIntent.ToggleHelp,
|
|
12
|
+
mode: Mode.DEFAULT,
|
|
13
|
+
action: () => setState(state => ({ ...state, viewHelp: !state.viewHelp })),
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
intent: KeyIntent.Confirm,
|
|
17
|
+
mode: Mode.DEFAULT,
|
|
18
|
+
description: '[ENTER] Confirm',
|
|
19
|
+
action: enterChildNode,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
intent: KeyIntent.Exit,
|
|
23
|
+
mode: Mode.DEFAULT,
|
|
24
|
+
description: '[E] Exit container',
|
|
25
|
+
action: exitToParentNode,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
intent: KeyIntent.NavPreviousItem,
|
|
29
|
+
mode: Mode.DEFAULT,
|
|
30
|
+
action: navigateToPreviousItem,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
intent: KeyIntent.NavNextItem,
|
|
34
|
+
mode: Mode.DEFAULT,
|
|
35
|
+
action: navigateToNextItem,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
intent: KeyIntent.NavToPreviousContainer,
|
|
39
|
+
mode: Mode.DEFAULT,
|
|
40
|
+
action: navigateToPreviousContainer,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
intent: KeyIntent.NavToNextContainer,
|
|
44
|
+
mode: Mode.DEFAULT,
|
|
45
|
+
action: navigateToNextContainer,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NavigationTree } from './types/navigation.model.js';
|
|
2
|
+
export interface NavigateCtx {
|
|
3
|
+
_selectedIndex: number;
|
|
4
|
+
breadCrumb: Array<NavigationTree<NavigationTree>>;
|
|
5
|
+
navigationNode: NavigationTree<NavigationTree>;
|
|
6
|
+
children: NavigationTree[];
|
|
7
|
+
getSelectedIndex(): number;
|
|
8
|
+
select(index: number): void;
|
|
9
|
+
selectNone(): void;
|
|
10
|
+
reInvokeNavigate(index: number, breadCrumb: NavigationTree<NavigationTree>[]): void;
|
|
11
|
+
render(): void;
|
|
12
|
+
confirm(selected: NavigationTree<NavigationTree>): void;
|
|
13
|
+
exit(): void;
|
|
14
|
+
enterChildNode(node: NavigationTree<NavigationTree>): void;
|
|
15
|
+
enterParentNode(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NavigationTree } from './types/navigation.model.js';
|
|
2
|
+
export declare function navigate<T extends NavigationTree>({ index, breadCrumb, callbacks, }: {
|
|
3
|
+
index: number;
|
|
4
|
+
breadCrumb: Array<NavigationTree<NavigationTree>>;
|
|
5
|
+
callbacks: Partial<{
|
|
6
|
+
render: () => void;
|
|
7
|
+
onSelectChange: (s: T['children'][number]) => void;
|
|
8
|
+
onConfirm: (s: T['children'][number]) => void;
|
|
9
|
+
}>;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import readline from 'readline';
|
|
2
|
+
import { navigationState } from './state.js';
|
|
3
|
+
import { getKeyIntent } from './utils/key-intent.js';
|
|
4
|
+
export function navigate({ index = 0, breadCrumb, callbacks, }) {
|
|
5
|
+
const { render = () => { }, onSelectChange = () => { }, onConfirm = () => { }, } = callbacks;
|
|
6
|
+
const ctx = {
|
|
7
|
+
breadCrumb,
|
|
8
|
+
get navigationNode() {
|
|
9
|
+
return this.breadCrumb.at(-1);
|
|
10
|
+
},
|
|
11
|
+
get children() {
|
|
12
|
+
return this.navigationNode.children ?? [];
|
|
13
|
+
},
|
|
14
|
+
selectNone: () => {
|
|
15
|
+
ctx.select(-1);
|
|
16
|
+
},
|
|
17
|
+
_selectedIndex: 0,
|
|
18
|
+
getSelectedIndex() {
|
|
19
|
+
return this._selectedIndex;
|
|
20
|
+
},
|
|
21
|
+
select(i) {
|
|
22
|
+
this._selectedIndex = i;
|
|
23
|
+
updateSelection(ctx.navigationNode, i, onSelectChange);
|
|
24
|
+
},
|
|
25
|
+
render,
|
|
26
|
+
reInvokeNavigate(index, breadCrumb) {
|
|
27
|
+
return reInvokeNavigate(index, breadCrumb);
|
|
28
|
+
},
|
|
29
|
+
confirm: sel => onConfirm(sel),
|
|
30
|
+
exit: () => {
|
|
31
|
+
cleanup();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
},
|
|
34
|
+
enterChildNode: node => reInvokeNavigate(0, [...breadCrumb, node]),
|
|
35
|
+
enterParentNode: () => {
|
|
36
|
+
ctx.select(-1); // Clear all on this level
|
|
37
|
+
if (breadCrumb.length < 2)
|
|
38
|
+
return; // Need at least grandparent + parent
|
|
39
|
+
const ancestors = breadCrumb;
|
|
40
|
+
const parent = ancestors[ancestors.length - 1];
|
|
41
|
+
const grandParent = ancestors[ancestors.length - 2];
|
|
42
|
+
if (!parent || !grandParent)
|
|
43
|
+
return;
|
|
44
|
+
const parentIndex = grandParent?.children.findIndex(x => parent.id === x.id);
|
|
45
|
+
reInvokeNavigate(parentIndex, breadCrumb.slice(0, -1)); // Go to parent level
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
ctx.select(index);
|
|
49
|
+
function onKeyPress(_, key) {
|
|
50
|
+
if (key.ctrl && key.name === 'c')
|
|
51
|
+
return ctx.exit();
|
|
52
|
+
const filteredActions = navigationState.availableActions.filter(x => x.mode === navigationState.mode);
|
|
53
|
+
const action = filteredActions?.find(actionMeta => {
|
|
54
|
+
const intent = getKeyIntent(key, ctx);
|
|
55
|
+
return intent === actionMeta.intent;
|
|
56
|
+
});
|
|
57
|
+
action?.action?.(ctx);
|
|
58
|
+
ctx.render();
|
|
59
|
+
}
|
|
60
|
+
const cleanup = () => process.stdin.removeListener('keypress', onKeyPress);
|
|
61
|
+
const reInvokeNavigate = (idx, crumb) => {
|
|
62
|
+
cleanup();
|
|
63
|
+
navigate({ index: idx, breadCrumb: [...crumb], callbacks });
|
|
64
|
+
};
|
|
65
|
+
render();
|
|
66
|
+
readline.emitKeypressEvents(process.stdin);
|
|
67
|
+
if (process.stdin.isTTY)
|
|
68
|
+
process.stdin.setRawMode(true);
|
|
69
|
+
process.stdin.on('keypress', onKeyPress);
|
|
70
|
+
}
|
|
71
|
+
function updateSelection({ children }, idx, onSelectChange) {
|
|
72
|
+
children.forEach((c, i) => (c.isSelected = i === idx));
|
|
73
|
+
onSelectChange(children[idx]);
|
|
74
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const COLORS: {
|
|
2
|
+
readonly green: "\u001B[32m";
|
|
3
|
+
readonly gray: "\u001B[90m";
|
|
4
|
+
readonly yellow: "\u001B[33m";
|
|
5
|
+
readonly red: "\u001B[31m";
|
|
6
|
+
readonly default: null;
|
|
7
|
+
};
|
|
8
|
+
export type HighlightColor = keyof typeof COLORS;
|
|
9
|
+
export declare const highlight: (str: string, color?: HighlightColor) => string;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const COLORS = {
|
|
2
|
+
green: "\x1b[32m",
|
|
3
|
+
gray: "\x1b[90m",
|
|
4
|
+
yellow: "\x1b[33m",
|
|
5
|
+
red: "\x1b[31m",
|
|
6
|
+
default: null, // no color
|
|
7
|
+
};
|
|
8
|
+
const RESET = "\x1b[0m";
|
|
9
|
+
export const highlight = (str, color = "default") => {
|
|
10
|
+
const prefix = COLORS[color];
|
|
11
|
+
return prefix ? `${prefix}${str}${RESET}` : str;
|
|
12
|
+
};
|