@copilotz/work 0.0.0-stage → 1.0.0-rc.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/boards/actions/create-board.d.ts +1 -0
- package/boards/actions/create-board.js +47 -0
- package/boards/actions/create-card.d.ts +1 -0
- package/boards/actions/create-card.js +83 -0
- package/boards/actions/delete-board.d.ts +1 -0
- package/boards/actions/delete-board.js +30 -0
- package/boards/actions/delete-card.d.ts +1 -0
- package/boards/actions/delete-card.js +24 -0
- package/boards/actions/move-card.d.ts +1 -0
- package/boards/actions/move-card.js +85 -0
- package/boards/actions/update-board.d.ts +1 -0
- package/boards/actions/update-board.js +110 -0
- package/boards/actions/update-card.d.ts +1 -0
- package/boards/actions/update-card.js +67 -0
- package/boards/collections/board.d.ts +71 -0
- package/boards/collections/board.js +32 -0
- package/boards/collections/card.d.ts +74 -0
- package/boards/collections/card.js +29 -0
- package/boards/contract.d.ts +67 -0
- package/boards/contract.js +20 -0
- package/boards/mod.d.ts +34 -0
- package/boards/mod.js +72 -0
- package/boards/resources/tools.d.ts +2 -0
- package/boards/resources/tools.js +414 -0
- package/boards/shared/columns.d.ts +39 -0
- package/boards/shared/columns.js +88 -0
- package/boards/shared/dates.d.ts +11 -0
- package/boards/shared/dates.js +22 -0
- package/boards/shared/errors.d.ts +24 -0
- package/boards/shared/errors.js +20 -0
- package/boards/shared/fields.d.ts +65 -0
- package/boards/shared/fields.js +44 -0
- package/boards/shared/load.d.ts +22 -0
- package/boards/shared/load.js +32 -0
- package/boards/shared/order.d.ts +30 -0
- package/boards/shared/order.js +47 -0
- package/boards/shared/people.d.ts +30 -0
- package/boards/shared/people.js +87 -0
- package/boards/shared/said.d.ts +28 -0
- package/boards/shared/said.js +30 -0
- package/boards/views/web/board-head.d.ts +62 -0
- package/boards/views/web/board-head.js +170 -0
- package/boards/views/web/board-page.d.ts +17 -0
- package/boards/views/web/board-page.js +97 -0
- package/boards/views/web/board-view.d.ts +40 -0
- package/boards/views/web/board-view.js +341 -0
- package/boards/views/web/boards-tab.d.ts +13 -0
- package/boards/views/web/boards-tab.js +109 -0
- package/boards/views/web/card-sheet.d.ts +47 -0
- package/boards/views/web/card-sheet.js +314 -0
- package/boards/views/web/card-tile.d.ts +29 -0
- package/boards/views/web/card-tile.js +20 -0
- package/boards/views/web/column.d.ts +38 -0
- package/boards/views/web/column.js +171 -0
- package/boards/views/web/drag.d.ts +36 -0
- package/boards/views/web/drag.js +276 -0
- package/boards/views/web/glyphs.d.ts +29 -0
- package/boards/views/web/glyphs.js +25 -0
- package/boards/views/web/load.d.ts +32 -0
- package/boards/views/web/load.js +33 -0
- package/boards/views/web/palette.d.ts +15 -0
- package/boards/views/web/palette.js +180 -0
- package/boards/views/web/pickers.d.ts +45 -0
- package/boards/views/web/pickers.js +83 -0
- package/boards/views/web/shown.d.ts +77 -0
- package/boards/views/web/shown.js +136 -0
- package/boards/views/web/step.d.ts +13 -0
- package/boards/views/web/step.js +41 -0
- package/boards/views/web/style.d.ts +10 -0
- package/boards/views/web/style.js +380 -0
- package/boards/views/web/toolbar.d.ts +21 -0
- package/boards/views/web/toolbar.js +39 -0
- package/boards/web.d.ts +26 -0
- package/boards/web.js +52 -0
- package/contract.d.ts +7 -0
- package/contract.js +7 -0
- package/documents/actions/create.d.ts +1 -0
- package/documents/actions/create.js +28 -0
- package/documents/actions/delete.d.ts +1 -0
- package/documents/actions/delete.js +32 -0
- package/documents/actions/presence.d.ts +1 -0
- package/documents/actions/presence.js +45 -0
- package/documents/actions/rename.d.ts +1 -0
- package/documents/actions/rename.js +33 -0
- package/documents/actions/restore.d.ts +1 -0
- package/documents/actions/restore.js +39 -0
- package/documents/actions/save.d.ts +1 -0
- package/documents/actions/save.js +78 -0
- package/documents/collections/document-presence.d.ts +79 -0
- package/documents/collections/document-presence.js +25 -0
- package/documents/collections/document-version.d.ts +166 -0
- package/documents/collections/document-version.js +60 -0
- package/documents/collections/document.d.ts +131 -0
- package/documents/collections/document.js +72 -0
- package/documents/contract.d.ts +17 -0
- package/documents/contract.js +1 -0
- package/documents/mod.d.ts +38 -0
- package/documents/mod.js +75 -0
- package/documents/resources/tools.d.ts +2 -0
- package/documents/resources/tools.js +253 -0
- package/documents/shared/diff.d.ts +37 -0
- package/documents/shared/diff.js +148 -0
- package/documents/shared/merge.d.ts +29 -0
- package/documents/shared/merge.js +120 -0
- package/documents/shared/presence.d.ts +7 -0
- package/documents/shared/presence.js +7 -0
- package/documents/shared/text.d.ts +36 -0
- package/documents/shared/text.js +67 -0
- package/documents/shared/who.d.ts +23 -0
- package/documents/shared/who.js +39 -0
- package/documents/shared/write.d.ts +54 -0
- package/documents/shared/write.js +123 -0
- package/documents/views/web/changes.d.ts +22 -0
- package/documents/views/web/changes.js +57 -0
- package/documents/views/web/conflict.d.ts +38 -0
- package/documents/views/web/conflict.js +96 -0
- package/documents/views/web/draft.d.ts +18 -0
- package/documents/views/web/draft.js +32 -0
- package/documents/views/web/editor.d.ts +57 -0
- package/documents/views/web/editor.js +268 -0
- package/documents/views/web/format.d.ts +56 -0
- package/documents/views/web/format.js +245 -0
- package/documents/views/web/history.d.ts +23 -0
- package/documents/views/web/history.js +118 -0
- package/documents/views/web/list.d.ts +37 -0
- package/documents/views/web/list.js +211 -0
- package/documents/views/web/page.d.ts +35 -0
- package/documents/views/web/page.js +416 -0
- package/documents/views/web/palette.d.ts +16 -0
- package/documents/views/web/palette.js +168 -0
- package/documents/views/web/people.d.ts +60 -0
- package/documents/views/web/people.js +63 -0
- package/documents/views/web/presence.d.ts +30 -0
- package/documents/views/web/presence.js +75 -0
- package/documents/views/web/step.d.ts +25 -0
- package/documents/views/web/step.js +81 -0
- package/documents/views/web/style.d.ts +7 -0
- package/documents/views/web/style.js +266 -0
- package/documents/web.d.ts +18 -0
- package/documents/web.js +46 -0
- package/mod.d.ts +18 -0
- package/mod.js +18 -0
- package/package.json +61 -4
- package/web.d.ts +13 -0
- package/web.js +13 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A board's page (kind `board`, at `/board/<id>`; `?card=<id>` opens a
|
|
3
|
+
* card): its name (renamed in place), its space, what it's for, its menu,
|
|
4
|
+
* then the board itself, filling the page and scrolling sideways. And a
|
|
5
|
+
* board shown inside something else (kind `board.inline`, item `{ _id }`,
|
|
6
|
+
* hints `{ in, mode }`): a space's tab with one board (`inline`), or the
|
|
7
|
+
* side panel beside a chat (`panel`, compact), its name a link to its page.
|
|
8
|
+
* Live: what others and agents change shows at once.
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactNode } from "react";
|
|
11
|
+
import type { ViewContext } from "copilotz";
|
|
12
|
+
export declare const boardPageView: (item: {
|
|
13
|
+
_id?: string;
|
|
14
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
15
|
+
export declare const boardInlineView: (item: {
|
|
16
|
+
_id?: string;
|
|
17
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A board's page (kind `board`, at `/board/<id>`; `?card=<id>` opens a
|
|
4
|
+
* card): its name (renamed in place), its space, what it's for, its menu,
|
|
5
|
+
* then the board itself, filling the page and scrolling sideways. And a
|
|
6
|
+
* board shown inside something else (kind `board.inline`, item `{ _id }`,
|
|
7
|
+
* hints `{ in, mode }`): a space's tab with one board (`inline`), or the
|
|
8
|
+
* side panel beside a chat (`panel`, compact), its name a link to its page.
|
|
9
|
+
* Live: what others and agents change shows at once.
|
|
10
|
+
*/
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import { Badge, Button, EmptyState, Menu, message, Notice, Page, Skeleton, Title, } from "copilotz/web";
|
|
13
|
+
import { boardPath, boardsTab } from "../../contract.js";
|
|
14
|
+
import { BoardAbout, boardMenu, BoardName, DeleteBoard, NewBoard } from "./board-head.js";
|
|
15
|
+
import { BoardView } from "./board-view.js";
|
|
16
|
+
import { Glyph } from "./glyphs.js";
|
|
17
|
+
import { boardData, placeName, placesOf } from "./load.js";
|
|
18
|
+
import { STYLE } from "./style.js";
|
|
19
|
+
const style = _jsx("style", { href: "boards-web", precedence: "copilotz", children: STYLE });
|
|
20
|
+
export const boardPageView = (item, ctx) => {
|
|
21
|
+
const id = item._id ?? "";
|
|
22
|
+
const board = ctx.db.collection("board").findOne({ _id: id }).value;
|
|
23
|
+
const places = placesOf(ctx);
|
|
24
|
+
const data = boardData(ctx, board);
|
|
25
|
+
const query = (ctx.hints.query ?? {});
|
|
26
|
+
if (board === undefined || !places)
|
|
27
|
+
return _jsx(Loading, { page: true });
|
|
28
|
+
if (!board) {
|
|
29
|
+
return (_jsxs("div", { className: "board-missing", children: [style, _jsx(Title, { text: "No such board" }), _jsx(EmptyState, { icon: "search", heading: "h1", title: "No board here", action: _jsx(Button, { variant: "primary", icon: "home", href: "/", children: "Go home" }), children: "It may have been deleted, or it's in a space you're not in." })] }));
|
|
30
|
+
}
|
|
31
|
+
const space = typeof ctx.hints.in === "string" ? ctx.hints.in : board.in;
|
|
32
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(BoardScreen, { board: board, data: data, place: places.find((p) => p._id === board.in), me: ctx.viewer?.name, mode: "page", space: space, opened: query.card, call: ctx.call }, board._id)] }));
|
|
33
|
+
};
|
|
34
|
+
export const boardInlineView = (item, ctx) => {
|
|
35
|
+
const board = ctx.db.collection("board").findOne({ _id: item._id ?? "" }).value;
|
|
36
|
+
const places = placesOf(ctx);
|
|
37
|
+
const data = boardData(ctx, board);
|
|
38
|
+
const mode = ctx.hints.mode === "panel" ? "panel" : "inline";
|
|
39
|
+
if (board === undefined || !places)
|
|
40
|
+
return _jsx(Loading, {});
|
|
41
|
+
if (!board)
|
|
42
|
+
return null;
|
|
43
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(BoardScreen, { board: board, data: data, place: places.find((p) => p._id === board.in), me: ctx.viewer?.name, mode: mode, space: typeof ctx.hints.in === "string" ? ctx.hints.in : board.in, call: ctx.call }, board._id)] }));
|
|
44
|
+
};
|
|
45
|
+
/** While a board loads: its shape, quietly. */
|
|
46
|
+
function Loading({ page }) {
|
|
47
|
+
const columns = (_jsx("div", { className: "board-loading-columns", "aria-busy": "true", children: [0, 1, 2, 3].map((i) => _jsx(Skeleton, { height: page ? 420 : 260, radius: "xl" }, i)) }));
|
|
48
|
+
if (!page)
|
|
49
|
+
return _jsxs("div", { className: "board-loading", children: [style, columns] });
|
|
50
|
+
return (_jsxs(Page, { title: _jsx(Skeleton, { width: 240, height: 30 }), width: "full", className: "board-page", children: [style, _jsxs("div", { className: "board-loading", children: [_jsx(Skeleton, { height: 34, width: 420 }), columns] })] }));
|
|
51
|
+
}
|
|
52
|
+
function BoardScreen({ board, data, place, me, mode, space, opened, call }) {
|
|
53
|
+
const [renaming, setRenaming] = useState(false);
|
|
54
|
+
const [describing, setDescribing] = useState(false);
|
|
55
|
+
const [deleting, setDeleting] = useState(false);
|
|
56
|
+
const [addingColumn, setAddingColumn] = useState(false);
|
|
57
|
+
const [making, setMaking] = useState(false);
|
|
58
|
+
const [error, setError] = useState();
|
|
59
|
+
const can = !!place?.can?.includes("write") && !place.archived;
|
|
60
|
+
const where = placeName(place);
|
|
61
|
+
const menu = boardMenu({
|
|
62
|
+
board,
|
|
63
|
+
can,
|
|
64
|
+
...(mode === "page" ? {} : { inline: { space } }),
|
|
65
|
+
onRename: () => setRenaming(true),
|
|
66
|
+
onDescribe: () => setDescribing(true),
|
|
67
|
+
onAddColumn: () => setAddingColumn(true),
|
|
68
|
+
onDelete: () => setDeleting(true),
|
|
69
|
+
...(mode === "page" ? {} : { onNewBoard: () => setMaking(true) }),
|
|
70
|
+
call: (action, input) => call(action, input).catch((e) => {
|
|
71
|
+
setError(message(e));
|
|
72
|
+
throw e;
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
const archived = board.archived
|
|
76
|
+
? (_jsx(Notice, { tone: "neutral", icon: "archive", title: "This board is archived", action: can
|
|
77
|
+
? (_jsx(Button, { size: "sm", icon: "restore", onClick: () => void call("board.update", { board: board._id, archived: false }).catch((e) => setError(message(e))), children: "Restore" }))
|
|
78
|
+
: undefined, children: "It's kept apart from the space's boards in use; its cards still change." }))
|
|
79
|
+
: null;
|
|
80
|
+
const failed = error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null;
|
|
81
|
+
const board$ = data.cards && data.people
|
|
82
|
+
? (_jsx(BoardView, { board: board, cards: data.cards, people: data.people, team: data.team, names: data.names, me: me, can: can, mode: mode, space: space, call: call, opened: opened, addingColumn: addingColumn, onAddingColumn: setAddingColumn, head: mode === "page" ? undefined : (_jsxs("div", { className: "board-head", children: [_jsxs("div", { className: "board-head-row", children: [_jsxs("h2", { className: "board-head-title", children: [_jsx(Glyph, { name: "board", size: 18 }), renaming
|
|
83
|
+
? (_jsx(BoardName, { board: board, can: can, renaming: true, onRenaming: setRenaming, call: call }))
|
|
84
|
+
: _jsx("a", { href: boardPath(board._id, space), children: board.name }), board.archived ? _jsx(Badge, { children: "Archived" }) : null] }), _jsx("div", { className: "board-head-actions", children: _jsx(Menu, { label: `${board.name}: more`, align: "end", size: "sm", items: menu }) })] }), mode === "inline" || describing
|
|
85
|
+
? (_jsx(BoardAbout, { board: board, can: can, writing: describing, onWriting: setDescribing, call: call }))
|
|
86
|
+
: null, archived, failed] })) }))
|
|
87
|
+
: (_jsx("div", { className: "board-loading-columns", "aria-busy": "true", children: [0, 1, 2, 3].map((i) => (_jsx(Skeleton, { height: mode === "page" ? 420 : 240, radius: "xl" }, i))) }));
|
|
88
|
+
const extras = (_jsxs(_Fragment, { children: [deleting
|
|
89
|
+
? (_jsx(DeleteBoard, { board: board, cards: data.cards?.length ?? 0, onClose: () => setDeleting(false), call: call, after: mode === "page" ? boardsTab(board.in) : undefined }))
|
|
90
|
+
: null, making
|
|
91
|
+
? _jsx(NewBoard, { space: board.in, where: where, onClose: () => setMaking(false), call: call })
|
|
92
|
+
: null] }));
|
|
93
|
+
if (mode !== "page") {
|
|
94
|
+
return (_jsxs(_Fragment, { children: [board$, extras] }));
|
|
95
|
+
}
|
|
96
|
+
return (_jsxs(Page, { title: _jsx(BoardName, { board: board, can: can, renaming: renaming, onRenaming: setRenaming, call: call }), leading: _jsx("span", { className: "copilotz-page-icon", children: _jsx(Glyph, { name: "board", size: 20 }) }), back: { href: boardsTab(board.in), label: `${where} · Board` }, badges: board.archived ? _jsx(Badge, { children: "Archived" }) : null, description: _jsx(BoardAbout, { board: board, can: can, writing: describing, onWriting: setDescribing, call: call }), actions: menu.length ? _jsx(Menu, { label: `${board.name}: more`, align: "end", items: menu }) : null, width: "full", className: "board-page", children: [_jsx(Title, { text: board.name }), archived, failed, board$, extras] }));
|
|
97
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A board, drawn: its filters, then its columns side by side (stacked in a
|
|
3
|
+
* side panel), each with its cards in order. Cards drag within and across
|
|
4
|
+
* columns (drag.ts): the others glide aside, a slot shows where it lands,
|
|
5
|
+
* and the move shows at once while it's on its way. With the keyboard, the
|
|
6
|
+
* arrows go from card to card; Space picks one up, the arrows carry it,
|
|
7
|
+
* Space puts it down and Escape puts it back, each step said aloud. A card
|
|
8
|
+
* opens its details; "New card" makes one in full; a column's foot adds one
|
|
9
|
+
* by its title. Everything follows the board live, as others change it.
|
|
10
|
+
*/
|
|
11
|
+
import { type ReactNode } from "react";
|
|
12
|
+
import type { Board, Card } from "../../contract.js";
|
|
13
|
+
import { type Names, type Someone, type Team } from "./shown.js";
|
|
14
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
15
|
+
export type BoardProps = {
|
|
16
|
+
board: Board;
|
|
17
|
+
cards: Card[];
|
|
18
|
+
/** The space's people and agents (and anyone cards already have). */
|
|
19
|
+
people: Someone[];
|
|
20
|
+
team?: Team;
|
|
21
|
+
/** People's names by id (their profiles'), for those cards name. */
|
|
22
|
+
names?: Names;
|
|
23
|
+
me?: string;
|
|
24
|
+
/** Whether the viewer may change it (an editor of its space). */
|
|
25
|
+
can: boolean;
|
|
26
|
+
/** On its page, inline in a space's tab, or compact beside a chat. */
|
|
27
|
+
mode: "page" | "inline" | "panel";
|
|
28
|
+
/** Where the person works, for links. */
|
|
29
|
+
space?: string;
|
|
30
|
+
call: Call;
|
|
31
|
+
/** A card the address asks to open (`?card=`). */
|
|
32
|
+
opened?: string;
|
|
33
|
+
/** The board's own column to add (its menu's "Add a column"). */
|
|
34
|
+
addingColumn?: boolean;
|
|
35
|
+
onAddingColumn?(open: boolean): void;
|
|
36
|
+
/** What goes over the filters: the board's name, inline. */
|
|
37
|
+
head?: ReactNode;
|
|
38
|
+
};
|
|
39
|
+
export declare function BoardView(props: BoardProps): ReactNode;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A board, drawn: its filters, then its columns side by side (stacked in a
|
|
4
|
+
* side panel), each with its cards in order. Cards drag within and across
|
|
5
|
+
* columns (drag.ts): the others glide aside, a slot shows where it lands,
|
|
6
|
+
* and the move shows at once while it's on its way. With the keyboard, the
|
|
7
|
+
* arrows go from card to card; Space picks one up, the arrows carry it,
|
|
8
|
+
* Space puts it down and Escape puts it back, each step said aloud. A card
|
|
9
|
+
* opens its details; "New card" makes one in full; a column's foot adds one
|
|
10
|
+
* by its title. Everything follows the board live, as others change it.
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
13
|
+
import { Button, message, Notice, openPalette, } from "copilotz/web";
|
|
14
|
+
import { todayOf } from "../../shared/dates.js";
|
|
15
|
+
import { byOrder, indexOf, orderAt } from "../../shared/order.js";
|
|
16
|
+
import { CardSheet, Sheet } from "./card-sheet.js";
|
|
17
|
+
import { CardTile } from "./card-tile.js";
|
|
18
|
+
import { ColumnView, NewColumn } from "./column.js";
|
|
19
|
+
import { useCardDrag } from "./drag.js";
|
|
20
|
+
import { byColumn, isDone, kept, labelsOn, NO_FILTERS, someoneOf, } from "./shown.js";
|
|
21
|
+
import { Toolbar } from "./toolbar.js";
|
|
22
|
+
/** How long a move may show where it's going before the board must say it's there. */
|
|
23
|
+
const PENDING_MS = 6000;
|
|
24
|
+
export function BoardView(props) {
|
|
25
|
+
const { board, cards, people, team, names, me, can, mode, space, call } = props;
|
|
26
|
+
const compact = mode === "panel";
|
|
27
|
+
const root = useRef(null);
|
|
28
|
+
const [filters, setFilters] = useState(NO_FILTERS);
|
|
29
|
+
const [pending, setPending] = useState({});
|
|
30
|
+
const [held, setHeld] = useState();
|
|
31
|
+
const [open, setOpen] = useState(props.opened);
|
|
32
|
+
const [making, setMaking] = useState();
|
|
33
|
+
const [adding, setAdding] = useState();
|
|
34
|
+
const [ownColumn, setOwnColumn] = useState(false);
|
|
35
|
+
const [folded, setFolded] = useState(() => compact ? Object.fromEntries(board.columns.filter(isDone).map((c) => [c.id, true])) : {});
|
|
36
|
+
const [said, setSaid] = useState("");
|
|
37
|
+
const [error, setError] = useState();
|
|
38
|
+
const today = todayOf();
|
|
39
|
+
const addingColumn = props.addingColumn ?? ownColumn;
|
|
40
|
+
const setAddingColumn = props.onAddingColumn ?? setOwnColumn;
|
|
41
|
+
// A card asked for by the address opens; one deleted meanwhile closes.
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (props.opened)
|
|
44
|
+
setOpen(props.opened);
|
|
45
|
+
}, [props.opened]);
|
|
46
|
+
const openCard = open ? cards.find((c) => c._id === open) : undefined;
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (open && !openCard && cards.length)
|
|
49
|
+
setOpen(undefined);
|
|
50
|
+
}, [open, !!openCard]);
|
|
51
|
+
// Moves on their way end once the board says the card is there (or after a while).
|
|
52
|
+
const latest = useRef(cards);
|
|
53
|
+
latest.current = cards;
|
|
54
|
+
const settle = (id, at) => setPending((all) => {
|
|
55
|
+
const card = latest.current.find((c) => c._id === id);
|
|
56
|
+
const there = !at || !card || (card.column === at.column && card.order === at.order);
|
|
57
|
+
const next = { ...all };
|
|
58
|
+
if (there)
|
|
59
|
+
delete next[id];
|
|
60
|
+
else
|
|
61
|
+
next[id] = { ...at, since: Date.now() };
|
|
62
|
+
return next;
|
|
63
|
+
});
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
const settled = Object.entries(pending).filter(([id, p]) => {
|
|
67
|
+
const card = cards.find((c) => c._id === id);
|
|
68
|
+
return !card || (card.column === p.column && card.order === p.order) ||
|
|
69
|
+
now - (p.since ?? now) > PENDING_MS;
|
|
70
|
+
});
|
|
71
|
+
if (settled.length) {
|
|
72
|
+
setPending((all) => {
|
|
73
|
+
const next = { ...all };
|
|
74
|
+
for (const [id] of settled)
|
|
75
|
+
delete next[id];
|
|
76
|
+
return next;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}, [cards]);
|
|
80
|
+
const who = (key) => people.find((p) => p.key === key) ?? someoneOf(key, team, me, names);
|
|
81
|
+
const columns = byColumn(board, cards, pending);
|
|
82
|
+
const visible = (column) => (columns.get(column) ?? []).filter((c) => kept(c, filters, (k) => who(k).name));
|
|
83
|
+
const shownCount = board.columns.reduce((n, c) => n + visible(c.id).length, 0);
|
|
84
|
+
/** Where a card dropped at `index` among a column's shown cards goes: next to its neighbours. */
|
|
85
|
+
const placeOf = (card, column, index) => {
|
|
86
|
+
const shown = visible(column).filter((c) => c._id !== card);
|
|
87
|
+
if (index < shown.length)
|
|
88
|
+
return { before: shown[index]._id };
|
|
89
|
+
return shown.length ? { after: shown[shown.length - 1]._id } : { at: "bottom" };
|
|
90
|
+
};
|
|
91
|
+
/** Moves a card: shown there at once, then the board's move; said aloud. */
|
|
92
|
+
const move = async (cardId, column, place) => {
|
|
93
|
+
const card = cards.find((c) => c._id === cardId);
|
|
94
|
+
if (!card || !can)
|
|
95
|
+
return;
|
|
96
|
+
const others = byOrder((columns.get(column) ?? []).filter((c) => c._id !== cardId));
|
|
97
|
+
const { order } = orderAt(others, indexOf(others, place));
|
|
98
|
+
setPending((all) => ({ ...all, [cardId]: { column, order, since: Date.now() } }));
|
|
99
|
+
const name = board.columns.find((c) => c.id === column)?.name ?? column;
|
|
100
|
+
try {
|
|
101
|
+
const done = await call("card.move", {
|
|
102
|
+
card: cardId,
|
|
103
|
+
column,
|
|
104
|
+
...place,
|
|
105
|
+
});
|
|
106
|
+
settle(cardId, { column: done.column, order: done.order });
|
|
107
|
+
setTimeout(() => settle(cardId), PENDING_MS);
|
|
108
|
+
setSaid(`Moved “${card.title}” to ${name}.`);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
settle(cardId);
|
|
112
|
+
setError(message(e));
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const drop = (cardId, column, index) => {
|
|
116
|
+
const card = cards.find((c) => c._id === cardId);
|
|
117
|
+
if (!card)
|
|
118
|
+
return;
|
|
119
|
+
const where = visible(column);
|
|
120
|
+
const at = where.findIndex((c) => c._id === cardId);
|
|
121
|
+
// Put back where it was: nothing to do.
|
|
122
|
+
if (at >= 0 && (index === at || (index === Infinity && at === where.length - 1)))
|
|
123
|
+
return;
|
|
124
|
+
void move(cardId, column, placeOf(cardId, column, index));
|
|
125
|
+
};
|
|
126
|
+
const drag = useCardDrag({ root, enabled: can, onDrop: drop });
|
|
127
|
+
const preview = drag.preview ?? held;
|
|
128
|
+
// Cards glide to where they now are, when a slot opens or the board changes under them.
|
|
129
|
+
const was = useRef(new Map());
|
|
130
|
+
useLayoutEffect(() => {
|
|
131
|
+
const box = root.current;
|
|
132
|
+
if (!box)
|
|
133
|
+
return;
|
|
134
|
+
const still = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
135
|
+
const now = new Map();
|
|
136
|
+
const gliding = [];
|
|
137
|
+
for (const el of box.querySelectorAll("[data-card]:not([data-lifted])")) {
|
|
138
|
+
const at = { list: el.parentElement?.dataset.list ?? "", top: el.offsetTop };
|
|
139
|
+
now.set(el.dataset.card, at);
|
|
140
|
+
const before = was.current.get(el.dataset.card);
|
|
141
|
+
const by = before && before.list === at.list ? before.top - at.top : 0;
|
|
142
|
+
if (!still && by && Math.abs(by) < 1600) {
|
|
143
|
+
el.style.transition = "none";
|
|
144
|
+
el.style.transform = `translateY(${by}px)`;
|
|
145
|
+
gliding.push(el);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
was.current = now;
|
|
149
|
+
if (!gliding.length)
|
|
150
|
+
return;
|
|
151
|
+
void box.offsetHeight;
|
|
152
|
+
for (const el of gliding) {
|
|
153
|
+
el.style.transition = "transform .2s cubic-bezier(.2, .8, .2, 1)";
|
|
154
|
+
el.style.transform = "";
|
|
155
|
+
el.addEventListener("transitionend", () => (el.style.transition = ""), { once: true });
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
// A card carried by the keyboard keeps the focus as it goes.
|
|
159
|
+
useLayoutEffect(() => {
|
|
160
|
+
if (held)
|
|
161
|
+
document.getElementById(`card-${held.card}`)?.focus();
|
|
162
|
+
}, [held?.column, held?.index]);
|
|
163
|
+
const columnOf = (id) => board.columns.findIndex((c) => c.id === id);
|
|
164
|
+
const keys = (event, card, column) => {
|
|
165
|
+
const list = visible(column);
|
|
166
|
+
const at = list.findIndex((c) => c._id === card._id);
|
|
167
|
+
const step = (id) => document.getElementById(`card-${id}`)?.focus();
|
|
168
|
+
if (held?.card === card._id) {
|
|
169
|
+
const others = (c) => visible(c).filter((x) => x._id !== card._id).length;
|
|
170
|
+
const go = (to, index) => {
|
|
171
|
+
const name = board.columns.find((c) => c.id === to)?.name ?? to;
|
|
172
|
+
setHeld({ ...held, column: to, index });
|
|
173
|
+
setSaid(`${name}, position ${index + 1} of ${others(to) + 1}.`);
|
|
174
|
+
};
|
|
175
|
+
const ci = columnOf(held.column);
|
|
176
|
+
const sideways = (by) => {
|
|
177
|
+
const next = board.columns[ci + by];
|
|
178
|
+
if (next)
|
|
179
|
+
go(next.id, Math.min(held.index, others(next.id)));
|
|
180
|
+
};
|
|
181
|
+
const moves = {
|
|
182
|
+
ArrowUp: () => held.index > 0 && go(held.column, held.index - 1),
|
|
183
|
+
ArrowDown: () => held.index < others(held.column) && go(held.column, held.index + 1),
|
|
184
|
+
ArrowLeft: () => sideways(-1),
|
|
185
|
+
ArrowRight: () => sideways(1),
|
|
186
|
+
" ": () => {
|
|
187
|
+
setHeld(undefined);
|
|
188
|
+
drop(card._id, held.column, held.index);
|
|
189
|
+
},
|
|
190
|
+
Enter: () => {
|
|
191
|
+
setHeld(undefined);
|
|
192
|
+
drop(card._id, held.column, held.index);
|
|
193
|
+
},
|
|
194
|
+
Escape: () => {
|
|
195
|
+
setHeld(undefined);
|
|
196
|
+
setSaid(`“${card.title}” is back where it was.`);
|
|
197
|
+
requestAnimationFrame(() => step(card._id));
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
if (event.key === "Tab") {
|
|
201
|
+
setHeld(undefined);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (moves[event.key]) {
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
event.stopPropagation();
|
|
207
|
+
moves[event.key]();
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (event.key === " " && can) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
const height = event.currentTarget.parentElement.offsetHeight;
|
|
214
|
+
setHeld({ card: card._id, column, index: at, height, by: "keyboard" });
|
|
215
|
+
setSaid(`Picked up “${card.title}”. Arrows move it, Space puts it down, Escape puts it back.`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const ci = columnOf(column);
|
|
219
|
+
const sideways = (by) => {
|
|
220
|
+
for (let i = ci + by; i >= 0 && i < board.columns.length; i += by) {
|
|
221
|
+
const there = visible(board.columns[i].id);
|
|
222
|
+
if (there.length)
|
|
223
|
+
return step(there[Math.min(Math.max(at, 0), there.length - 1)]._id);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const moves = {
|
|
227
|
+
ArrowUp: () => list[at - 1] && step(list[at - 1]._id),
|
|
228
|
+
ArrowDown: () => list[at + 1] && step(list[at + 1]._id),
|
|
229
|
+
ArrowLeft: () => sideways(-1),
|
|
230
|
+
ArrowRight: () => sideways(1),
|
|
231
|
+
};
|
|
232
|
+
if (moves[event.key]) {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
moves[event.key]();
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
/** "Move to…": the board's columns, in the command palette. */
|
|
238
|
+
const moveStep = (card) => ({
|
|
239
|
+
title: `Move “${card.title.length > 40 ? `${card.title.slice(0, 39)}…` : card.title}” to…`,
|
|
240
|
+
placeholder: "Find a column",
|
|
241
|
+
items: () => [{
|
|
242
|
+
title: "",
|
|
243
|
+
items: board.columns.map((c) => ({
|
|
244
|
+
key: `board:move:${c.id}`,
|
|
245
|
+
label: c.name,
|
|
246
|
+
icon: c.id === card.column ? "check" : "chevron",
|
|
247
|
+
description: c.id === card.column ? "Where it is" : undefined,
|
|
248
|
+
disabled: c.id === card.column,
|
|
249
|
+
run: () => move(card._id, c.id, { at: "bottom" }),
|
|
250
|
+
})),
|
|
251
|
+
}],
|
|
252
|
+
});
|
|
253
|
+
const menuOf = (card) => [
|
|
254
|
+
{ label: "Open", icon: "external", onSelect: () => setOpen(card._id) },
|
|
255
|
+
...(can
|
|
256
|
+
? [
|
|
257
|
+
{ label: "Move to…", icon: "move", onSelect: () => openPalette(moveStep(card)) },
|
|
258
|
+
{
|
|
259
|
+
label: "Move to the top",
|
|
260
|
+
icon: "send",
|
|
261
|
+
onSelect: () => void move(card._id, card.column, { at: "top" }),
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
label: "Move to the bottom",
|
|
265
|
+
icon: "down",
|
|
266
|
+
onSelect: () => void move(card._id, card.column, { at: "bottom" }),
|
|
267
|
+
},
|
|
268
|
+
...(me && card.assignee !== `person:${me}`
|
|
269
|
+
? [{
|
|
270
|
+
label: "Take it",
|
|
271
|
+
icon: "person",
|
|
272
|
+
onSelect: () => void call("card.update", { card: card._id, assignee: `person:${me}` }).catch((e) => setError(message(e))),
|
|
273
|
+
}]
|
|
274
|
+
: []),
|
|
275
|
+
"separator",
|
|
276
|
+
{
|
|
277
|
+
label: "Delete",
|
|
278
|
+
icon: "trash",
|
|
279
|
+
tone: "destructive",
|
|
280
|
+
onSelect: () => void call("card.delete", { card: card._id }).catch((e) => setError(message(e))),
|
|
281
|
+
},
|
|
282
|
+
]
|
|
283
|
+
: []),
|
|
284
|
+
];
|
|
285
|
+
const changeColumns = (next, into) => call("board.update", { board: board._id, columns: next, ...(into ? { into } : {}) });
|
|
286
|
+
const help = `board-help-${board._id}`;
|
|
287
|
+
const list = (column) => {
|
|
288
|
+
const shown = visible(column.id);
|
|
289
|
+
const carried = preview?.by === "keyboard"
|
|
290
|
+
? cards.find((c) => c._id === preview.card)
|
|
291
|
+
: undefined;
|
|
292
|
+
const items = [];
|
|
293
|
+
const tile = (card, extra = {}) => (_jsx(CardTile, { card: card, done: isDone(column), today: today, owner: card.assignee ? who(card.assignee) : undefined, lifted: extra.lifted, held: extra.held, busy: !!pending[card._id] && !extra.held, menu: menuOf(card), describedBy: can ? help : undefined, onOpen: () => {
|
|
294
|
+
if (drag.justDragged() || held)
|
|
295
|
+
return;
|
|
296
|
+
setOpen(card._id);
|
|
297
|
+
}, onPress: (event) => drag.press(event, card._id, column.id), onKeys: (event) => keys(event, card, extra.held ? preview.column : column.id) }, card._id));
|
|
298
|
+
const landing = () => preview?.by === "pointer"
|
|
299
|
+
? (_jsx("li", { className: "board-slot", "data-slot": true, "aria-hidden": "true", style: { height: preview.height } }, "slot"))
|
|
300
|
+
: carried
|
|
301
|
+
? tile(carried, { held: true })
|
|
302
|
+
: null;
|
|
303
|
+
let k = 0;
|
|
304
|
+
const here = preview && preview.column === column.id;
|
|
305
|
+
for (const card of shown) {
|
|
306
|
+
if (carried && card._id === carried._id)
|
|
307
|
+
continue;
|
|
308
|
+
const lifted = preview?.by === "pointer" && card._id === preview.card;
|
|
309
|
+
if (here && !lifted && k === preview.index)
|
|
310
|
+
items.push(landing());
|
|
311
|
+
items.push(tile(card, { lifted }));
|
|
312
|
+
if (!lifted)
|
|
313
|
+
k++;
|
|
314
|
+
}
|
|
315
|
+
if (here && k <= preview.index)
|
|
316
|
+
items.push(landing());
|
|
317
|
+
return (_jsx("ul", { className: "board-list", "data-list": column.id, "data-folded": compact && folded[column.id] ? "" : undefined, "aria-label": `${column.name}'s cards`, children: items }));
|
|
318
|
+
};
|
|
319
|
+
return (_jsxs("div", { className: "board", "data-mode": mode, ref: root, children: [props.head, _jsx(Toolbar, { cards: cards, people: people, filters: filters, onFilters: setFilters, shown: shownCount, can: can, compact: compact, onNew: () => setMaking(board.columns[0]?.id) }), error
|
|
320
|
+
? (_jsx(Notice, { tone: "destructive", role: "alert", title: "That didn't work", action: _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setError(undefined), children: "Dismiss" }), children: error }))
|
|
321
|
+
: null, _jsxs("div", { className: "board-scroller", "data-scroller": true, children: [board.columns.map((column, i) => {
|
|
322
|
+
const total = (columns.get(column.id) ?? []).length;
|
|
323
|
+
return (_jsx(ColumnView, { column: column, index: i, columns: board.columns, total: total, shown: visible(column.id).length, can: can, compact: compact, over: preview?.by === "pointer" && preview.column === column.id, folded: compact && !!folded[column.id], onFold: () => setFolded((f) => ({ ...f, [column.id]: !f[column.id] })), adding: adding === column.id, onAdding: (on) => {
|
|
324
|
+
setAdding(on ? column.id : undefined);
|
|
325
|
+
if (on)
|
|
326
|
+
setFolded((f) => ({ ...f, [column.id]: false }));
|
|
327
|
+
}, onAdd: async (title) => {
|
|
328
|
+
await call("card.create", { board: board._id, title, column: column.id });
|
|
329
|
+
setSaid(`Added “${title}” to ${column.name}.`);
|
|
330
|
+
}, onChange: (next) => changeColumns(next), onRemove: (into) => changeColumns(board.columns.filter((c) => c.id !== column.id), into), children: list(column) }, column.id));
|
|
331
|
+
}), can
|
|
332
|
+
? (_jsx(NewColumn, { open: addingColumn, onOpen: setAddingColumn, onAdd: async (name) => {
|
|
333
|
+
await changeColumns([...board.columns, { name }]);
|
|
334
|
+
setSaid(`Added the column ${name}.`);
|
|
335
|
+
} }))
|
|
336
|
+
: null] }), _jsx("p", { id: help, hidden: true, children: "Enter opens it. Space picks it up to move it with the arrow keys." }), _jsx("p", { className: "board-sr", "aria-live": "assertive", children: said }), openCard
|
|
337
|
+
? (_jsx(Sheet, { open: true, onClose: () => setOpen(undefined), label: openCard.title, children: _jsx(CardSheet, { board: board, card: openCard, people: people, team: team, names: names, me: me, labels: labelsOn(cards).map((l) => l.label), today: today, can: can, space: space, call: call, onClose: () => setOpen(undefined), onMove: (card, column, at) => move(card._id, column, { at: at ?? "bottom" }) }, openCard._id) }))
|
|
338
|
+
: null, making
|
|
339
|
+
? (_jsx(Sheet, { open: true, onClose: () => setMaking(undefined), label: `New card on ${board.name}`, children: _jsx(CardSheet, { board: board, column: making, people: people, team: team, names: names, me: me, labels: labelsOn(cards).map((l) => l.label), today: today, can: can, space: space, call: call, onClose: () => setMaking(undefined), onMove: async () => { } }) }))
|
|
340
|
+
: null] }));
|
|
341
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A space's boards (kind `boards.tab`: spaces' Board tab, item `{ _id }`,
|
|
3
|
+
* hints `{ in, mode }`). With none, what a board is for, and one made in a
|
|
4
|
+
* click; with one, the board itself, inline; with several, each with how
|
|
5
|
+
* its work stands (a bar of its columns), opening its page, and those
|
|
6
|
+
* archived apart. Beside a chat (`mode: "panel"`), compact: the board, or a
|
|
7
|
+
* choice of boards and the one chosen.
|
|
8
|
+
*/
|
|
9
|
+
import { type ReactNode } from "react";
|
|
10
|
+
import type { ViewContext } from "copilotz";
|
|
11
|
+
export declare const boardsTabView: (item: {
|
|
12
|
+
_id?: string;
|
|
13
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A space's boards (kind `boards.tab`: spaces' Board tab, item `{ _id }`,
|
|
4
|
+
* hints `{ in, mode }`). With none, what a board is for, and one made in a
|
|
5
|
+
* click; with one, the board itself, inline; with several, each with how
|
|
6
|
+
* its work stands (a bar of its columns), opening its page, and those
|
|
7
|
+
* archived apart. Beside a chat (`mode: "panel"`), compact: the board, or a
|
|
8
|
+
* choice of boards and the one chosen.
|
|
9
|
+
*/
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { Button, EmptyState, LazyView, message, Notice, Select, Skeleton, Time, } from "copilotz/web";
|
|
12
|
+
import { boardPath } from "../../contract.js";
|
|
13
|
+
import { DEFAULT_COLUMNS, stageOf } from "../../shared/columns.js";
|
|
14
|
+
import { NewBoard } from "./board-head.js";
|
|
15
|
+
import { Glyph, StageMark } from "./glyphs.js";
|
|
16
|
+
import { placeName, placesOf } from "./load.js";
|
|
17
|
+
import { counted } from "./shown.js";
|
|
18
|
+
import { STYLE } from "./style.js";
|
|
19
|
+
const style = _jsx("style", { href: "boards-web", precedence: "copilotz", children: STYLE });
|
|
20
|
+
const byMade = (boards) => [...boards].sort((a, b) => a.at.localeCompare(b.at));
|
|
21
|
+
/** What the empty tab says about agents: the app's `boardsText.agentHint`, else this. */
|
|
22
|
+
const hintOf = (ctx) => ctx.resources.boardsText?.agentHint ??
|
|
23
|
+
"Agents read boards too: ask one to set it up, or to move a card for you.";
|
|
24
|
+
export const boardsTabView = (item, ctx) => {
|
|
25
|
+
const space = item._id ?? (typeof ctx.hints.in === "string" ? ctx.hints.in : "");
|
|
26
|
+
const compact = ctx.hints.mode === "panel";
|
|
27
|
+
const boards = ctx.db.collection("board").find({ in: space }).value;
|
|
28
|
+
const places = placesOf(ctx);
|
|
29
|
+
if (!boards || !places) {
|
|
30
|
+
return (_jsxs("div", { className: "boards", "aria-busy": "true", children: [style, _jsx(Skeleton, { height: compact ? 40 : 34, width: "50%" }), _jsx("div", { className: "board-loading-columns", children: [0, 1, 2].map((i) => _jsx(Skeleton, { height: compact ? 120 : 260, radius: "xl" }, i)) })] }));
|
|
31
|
+
}
|
|
32
|
+
const place = places.find((p) => p._id === space);
|
|
33
|
+
const can = !!place?.can?.includes("write") && !place.archived;
|
|
34
|
+
const active = byMade(boards.filter((b) => !b.archived));
|
|
35
|
+
const archived = byMade(boards.filter((b) => b.archived));
|
|
36
|
+
if (active.length === 1) {
|
|
37
|
+
const board = ctx.show("board.inline", { _id: active[0]._id }, {
|
|
38
|
+
in: space,
|
|
39
|
+
mode: compact ? "panel" : "inline",
|
|
40
|
+
});
|
|
41
|
+
if (!archived.length || compact)
|
|
42
|
+
return board;
|
|
43
|
+
// Its archived boards stay within reach, folded under it.
|
|
44
|
+
return (_jsxs("div", { className: "boards", children: [style, board, _jsx(Archived, { boards: archived, space: space })] }));
|
|
45
|
+
}
|
|
46
|
+
// The cards of several boards, for how each stands (only when there are several to list).
|
|
47
|
+
const cards = active.length > 1 && !compact
|
|
48
|
+
? ctx.db.collection("card").find({ in: space }).value
|
|
49
|
+
: [];
|
|
50
|
+
return (_jsxs("div", { className: `boards${compact ? " boards-compact" : ""}`, children: [style, _jsx(Boards, { space: space, place: place, can: can, active: active, archived: archived, cards: cards, compact: compact, call: ctx.call, hint: hintOf(ctx) })] }));
|
|
51
|
+
};
|
|
52
|
+
function Boards({ space, place, can, active, archived, cards, compact, call, hint }) {
|
|
53
|
+
const [making, setMaking] = useState(false);
|
|
54
|
+
const [chosen, setChosen] = useState();
|
|
55
|
+
const where = placeName(place);
|
|
56
|
+
const form = making
|
|
57
|
+
? (_jsx(NewBoard, { space: space, where: where, onClose: () => setMaking(false), call: call, open: !compact && active.length > 0 }))
|
|
58
|
+
: null;
|
|
59
|
+
if (!active.length) {
|
|
60
|
+
return (_jsxs(_Fragment, { children: [_jsx(Empty, { space: space, where: where, can: can, compact: compact, call: call, hint: hint }), archived.length ? _jsx(Archived, { boards: archived, space: space }) : null, form] }));
|
|
61
|
+
}
|
|
62
|
+
if (compact) {
|
|
63
|
+
const shown = active.find((b) => b._id === chosen) ?? active[0];
|
|
64
|
+
return (_jsxs(_Fragment, { children: [active.length > 1
|
|
65
|
+
? (_jsx("div", { className: "boards-head", children: _jsx(Select, { size: "sm", "aria-label": "Which board", value: shown._id, onChange: (event) => setChosen(event.target.value), children: active.map((b) => _jsx("option", { value: b._id, children: b.name }, b._id)) }) }))
|
|
66
|
+
: null, _jsx(LazyView, { kind: "board.inline", item: { _id: shown._id }, hints: { in: space, mode: "panel" }, fallback: _jsx(Skeleton, { height: 160, radius: "xl" }) }), form] }));
|
|
67
|
+
}
|
|
68
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "boards-head", children: [_jsxs("p", { className: "boards-intro", children: ["Where the work in ", where, " ", "stands: one real outcome per card, with its owner and an honest column. Agents here read and keep these too."] }), can
|
|
69
|
+
? _jsx(Button, { variant: "primary", icon: "plus", onClick: () => setMaking(true), children: "New board" })
|
|
70
|
+
: null] }), _jsx("ul", { className: "boards-list", children: active.map((b) => _jsx(BoardItem, { board: b, space: space, cards: cards }, b._id)) }), archived.length ? _jsx(Archived, { boards: archived, space: space }) : null, form] }));
|
|
71
|
+
}
|
|
72
|
+
/** A board in a space's list: its name, what it's for, how its work stands, when it last changed. */
|
|
73
|
+
function BoardItem({ board, space, cards }) {
|
|
74
|
+
const mine = (cards ?? []).filter((c) => c.board === board._id);
|
|
75
|
+
const latest = [board.updated ?? board.at, ...mine.map((c) => c.updated ?? c.at)].sort().at(-1);
|
|
76
|
+
const stages = board.columns.map((c) => ({
|
|
77
|
+
column: c,
|
|
78
|
+
n: mine.filter((card) => card.column === c.id).length,
|
|
79
|
+
})).filter((s) => s.n);
|
|
80
|
+
const done = stages.filter((s) => stageOf(s.column) === "done").reduce((n, s) => n + s.n, 0);
|
|
81
|
+
return (_jsx("li", { children: _jsxs("a", { className: "boards-item", href: boardPath(board._id, space), children: [_jsxs("span", { className: "boards-item-name", children: [_jsx(Glyph, { name: "board", size: 17 }), _jsx("span", { children: board.name })] }), board.description ? _jsx("p", { className: "boards-item-about", children: board.description }) : null, mine.length
|
|
82
|
+
? (_jsx("span", { className: "boards-bar", role: "img", "aria-label": stages.map((s) => `${s.column.name} ${s.n}`).join(", "), children: stages.map((s) => (_jsx("span", { "data-stage": stageOf(s.column), style: { flex: s.n } }, s.column.id))) }))
|
|
83
|
+
: null, _jsxs("span", { className: "boards-item-meta", children: [_jsx("span", { children: mine.length ? counted(mine.length) : "No cards yet" }), mine.length ? _jsxs("span", { children: ["\u00B7 ", done, " done"] }) : null, _jsxs("span", { children: ["\u00B7 ", _jsx(Time, { at: latest })] })] })] }) }));
|
|
84
|
+
}
|
|
85
|
+
function Archived({ boards, space }) {
|
|
86
|
+
return (_jsxs("details", { className: "boards-archived", children: [_jsxs("summary", { children: ["Archived (", boards.length, ")"] }), _jsx("ul", { className: "boards-list", children: boards.map((b) => _jsx(BoardItem, { board: b, space: space }, b._id)) })] }));
|
|
87
|
+
}
|
|
88
|
+
/** No board yet: what one is for, and one made in a click (renamed in place after). */
|
|
89
|
+
function Empty({ space, where, can, compact, call, hint }) {
|
|
90
|
+
const [busy, setBusy] = useState(false);
|
|
91
|
+
const [error, setError] = useState();
|
|
92
|
+
const make = async () => {
|
|
93
|
+
setBusy(true);
|
|
94
|
+
setError(undefined);
|
|
95
|
+
try {
|
|
96
|
+
await call("board.create", {
|
|
97
|
+
in: space,
|
|
98
|
+
name: where === "Personal" ? "My board" : `${where} board`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
setError(message(e));
|
|
103
|
+
setBusy(false);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return (_jsxs("div", { className: "boards-empty", children: [_jsxs(EmptyState, { icon: "check-circle", tone: "primary", title: "Keep the work on a board", action: can
|
|
107
|
+
? (_jsx(Button, { variant: "primary", icon: "plus", loading: busy, onClick: () => void make(), children: "Make a board" }))
|
|
108
|
+
: null, children: ["One real outcome per card, with its owner, an honest column, and any blocker. Agents here read it before they act and move cards as the work moves.", " ", can ? "" : `Editors of ${where} make boards here.`] }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, compact ? null : (_jsxs(_Fragment, { children: [_jsx("div", { className: "boards-preview", "aria-hidden": "true", children: DEFAULT_COLUMNS.map((c, i) => (_jsxs("div", { className: "boards-preview-column", children: [_jsxs("b", { children: [_jsx(StageMark, { stage: stageOf(c), size: 12 }), c.name] }), Array.from({ length: [2, 3, 2, 1, 1, 2][i] }, (_, n) => _jsx("span", { className: "boards-preview-card" }, n))] }, c.id))) }), _jsxs("ol", { className: "boards-teach", "aria-label": "How a board works", children: [_jsxs("li", { children: [_jsx("b", { children: "One outcome per card" }), _jsx("span", { children: "Something real that will be done, not a process step." })] }), _jsxs("li", { children: [_jsx("b", { children: "An owner, an honest column" }), _jsx("span", { children: "A person or an agent; moved when the state changes." })] }), _jsxs("li", { children: [_jsx("b", { children: "Read by agents too" }), _jsx("span", { children: hint })] })] })] }))] }));
|
|
109
|
+
}
|