markanban 0.0.0-stage → 0.1.6
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 +243 -2
- package/dist/board.js +250 -0
- package/dist/card.js +284 -0
- package/dist/cli.js +108 -0
- package/dist/demo.js +200 -0
- package/dist/server.js +378 -0
- package/dist/stats.js +197 -0
- package/dist/storage.js +316 -0
- package/package.json +55 -4
- package/public/app.js +966 -0
- package/public/charts.js +95 -0
- package/public/fonts/LICENSE-covered-by-your-grace.txt +93 -0
- package/public/fonts/LICENSE-permanent-marker.txt +202 -0
- package/public/fonts/covered-by-your-grace.woff2 +0 -0
- package/public/fonts/permanent-marker.woff2 +0 -0
- package/public/index.html +137 -0
- package/public/style.css +233 -0
- package/public/themes/dark.css +28 -0
- package/public/themes/whiteboard.css +323 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcus Hammarberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,244 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Markanban
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn a folder of markdown files into a live kanban board. Each file is a card, and every change is saved back to the file. Point it at a folder and you're done: the board is built from what's in the files. No database, no account, no setup.
|
|
4
|
+
|
|
5
|
+
The folder is the database: cards, lanes, attachments, settings and history are all plain files in it, so copying the folder copies the whole board. Your cards stay plain markdown files. Edit them in the board, in your editor, or both at the same time; the board updates live.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
You need [Node.js](https://nodejs.org) 22.18 or newer.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx markanban ./my-board
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This opens the board in your browser at <http://localhost:4242>. The folder is created if it doesn't exist yet; leave it out to use the current one. The first run takes a little longer while it downloads.
|
|
16
|
+
|
|
17
|
+
To try the latest unreleased version straight from GitHub (it builds on the first run): `npx github:marcus-hammarberg/markanban ./my-board`.
|
|
18
|
+
|
|
19
|
+
| Option | What it does |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `--port 4242` | Port to run on |
|
|
22
|
+
| `--user anna` | Your name in comments and history (see [Who you are](#who-you-are)) |
|
|
23
|
+
| `--no-open` | Don't open the browser automatically |
|
|
24
|
+
| `--export stats.json` | Write the board's status history as JSON for [Statsinator](#exporting-to-statsinator), then exit |
|
|
25
|
+
| `--help` | Show usage |
|
|
26
|
+
|
|
27
|
+
### Starting a new board
|
|
28
|
+
|
|
29
|
+
A new, empty board shows only **+ Column**. Click it to add your first column (for example `todo`), then use the **+** in that column to create your first card. Or just drop a few `.md` files into the folder; they show up right away.
|
|
30
|
+
|
|
31
|
+
## Cards
|
|
32
|
+
|
|
33
|
+
A card is any `.md` file directly in the folder, or in a lane folder (see [Swimlanes](#swimlanes)). `README.md` and hidden files are ignored. A file doesn't need anything special to be a card:
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
Just an idea I had.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
That shows up in a **No status** column. Add front-matter to give it more:
|
|
40
|
+
|
|
41
|
+
```markdown
|
|
42
|
+
---
|
|
43
|
+
status: doing
|
|
44
|
+
type: bug
|
|
45
|
+
assignee: anna
|
|
46
|
+
tags: ui, auth
|
|
47
|
+
priority: high
|
|
48
|
+
---
|
|
49
|
+
# Fix login bug
|
|
50
|
+
|
|
51
|
+
Users get logged out after 5 minutes.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Every field is optional:
|
|
55
|
+
|
|
56
|
+
| Field | Meaning |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `status` | The column the card is in |
|
|
59
|
+
| `type` | Free text, e.g. `bug` or `feature`; also sets the card's [color](#colors) |
|
|
60
|
+
| `assignee` | Who is working on it |
|
|
61
|
+
| `tags` | `ui, auth` or `[ui, auth]` |
|
|
62
|
+
| `heading` | The card title. Without it, the first `# Heading` in the text is used, then the file name (`fix-login-bug.md` → "fix login bug") |
|
|
63
|
+
|
|
64
|
+
Any other field (like `priority` above) is kept as-is and shown as a small label on the card. Markanban also adds a `rank` field when you reorder cards; it stores the card's position and isn't shown.
|
|
65
|
+
|
|
66
|
+
## Columns
|
|
67
|
+
|
|
68
|
+
Columns come from the statuses on your cards, so a new status gives you a new column. They're ordered the way you'd expect (`backlog`, `todo`, `ready`, `doing`, `in progress`, `review`, `done`), with any others after them alphabetically.
|
|
69
|
+
|
|
70
|
+
To change the order, drag a column by its header (⠿), or hover over the header and use the ‹ › buttons. Your order is saved in `.markanban.yml`, and columns listed there stay visible even when they're empty. A column also stays when you move or archive its last card on the board. Use **+ Column** to add a new one, or drop a card on it to give the card a new status.
|
|
71
|
+
|
|
72
|
+
### WIP limits
|
|
73
|
+
|
|
74
|
+
Give a column a work-in-progress limit in `.markanban.yml`:
|
|
75
|
+
|
|
76
|
+
```yaml
|
|
77
|
+
wip:
|
|
78
|
+
doing: 3
|
|
79
|
+
review: 2
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The column header then shows `2 / 3`: every card in the column, in all swimlanes, against the limit. Filters don't change that number, and archived cards don't count. When a column goes over its limit, it turns red and the header shows ⚠. You can still move cards into it; the limit is a signal for the team, not a lock. Replay shows when columns went over (against today's limits), which is handy in a retrospective.
|
|
83
|
+
|
|
84
|
+
## Swimlanes
|
|
85
|
+
|
|
86
|
+
Swimlanes are rows across the board, one per folder, all sharing the same columns. To add one, create a folder in the board folder and put (or move) a card file into it:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
team-board/
|
|
90
|
+
triage-inbox.md ← top row, without a header
|
|
91
|
+
1 Frontend/
|
|
92
|
+
login-button.md ← the "1 Frontend" lane
|
|
93
|
+
2 Backend/
|
|
94
|
+
rate-limit.md
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- A folder is a lane as long as it holds at least one card. Empty folders and folders without cards (`images/`, say) don't show.
|
|
98
|
+
- A folder next to a card with the same name (`login-button/` next to `login-button.md`) holds that card's [attachments](#attachments), so it isn't a lane.
|
|
99
|
+
- Lanes are sorted by name. Put a number in front (`1 Frontend`, `2 Backend`) to choose the order.
|
|
100
|
+
- Lanes are one folder deep: folders inside a lane aren't lanes, and a warning tells you if cards are hiding there.
|
|
101
|
+
- Drag a card into another lane to move it there; its file and attachments move along, and the history records `lane: 1 Frontend → 2 Backend`. With the keyboard, Alt+↑/↓ past the top or bottom of a lane moves the card into the lane above or below. A card can't move into a lane that already has a file with the same name.
|
|
102
|
+
- Click a lane's name to collapse it to one line (click again to open it). Each person's collapsed lanes are remembered in their own browser.
|
|
103
|
+
- New cards from **+** start in the top row. Board links to a card keep working after it moves to another lane.
|
|
104
|
+
|
|
105
|
+
Lanes are made and renamed in Finder or Explorer, not on the board. Boards without folders look exactly as before.
|
|
106
|
+
|
|
107
|
+
## Working with cards
|
|
108
|
+
|
|
109
|
+
- **Move** a card by dragging it to another column, or up and down within one. The order is your priority: the top card matters most. A line shows where the card will land.
|
|
110
|
+
- **Keyboard**: Tab to a card, Enter opens it, Alt+↑/↓ moves it up or down, Alt+←/→ moves it to the next column.
|
|
111
|
+
- **Create** a card with the **+** in a column header. It becomes a new file named after its heading.
|
|
112
|
+
- **Edit** by clicking a card: change its fields and text, then **Save** (or press Ctrl/⌘+Enter).
|
|
113
|
+
If someone changes the card's text in the folder while you're editing it, a banner says so. Your text stays put; you can look at theirs, discard yours, or save yours anyway.
|
|
114
|
+
- **Link** to a card with the 🔗 in its dialog: it copies an address (like `http://localhost:4242/#card=fix-login-bug.md`) that opens the card. Teammates need to use the same port.
|
|
115
|
+
- **Comment** in the Comments section at the bottom of the card (collapsed until you open it, with the number of comments shown). Comments are saved in the card file.
|
|
116
|
+
- **Attach files** in the Attachments section of the card: **Add file**, drop a file on the card, or paste one (a screenshot, say). See [Attachments](#attachments).
|
|
117
|
+
- **Archive** cards you're done with. They disappear from the board; tick **Show archived** to see them again and unarchive. There's no delete button: to remove a card for good, delete its file.
|
|
118
|
+
- **Filter** with the row above the board: search text (headings, card text, comments and attachment names), or pick a type, assignee or tag.
|
|
119
|
+
- **Replay** shows how the board got here: **▶ Replay** in the top right plays back how cards moved between columns, 8 hours per second. Drag the slider to jump around, and use the filters to follow one person or tag. The board is read-only while replaying; **Exit replay** brings back the live board.
|
|
120
|
+
- **Stats** shows how work flows, from the card history: **Stats** in the top right opens three charts. **Lead time** is how many days each card took from the start column (or from when it was created: pick *Card created*) to the end column you pick (dots, with lines where half and 85% of cards finished); click a dot to open the card. **Throughput** is how many cards reached the end column per day, week or month (pick one next to the chart). **Work in progress** is how many cards sat in each column at the end of every day; tick the columns to count. Pick a type to look at one kind of card, and a date range (the last 12 weeks to begin with). **Back to board** returns.
|
|
121
|
+
- **Theme**: the board follows your system's light or dark mode. The theme menu in the top right picks System, Light, Dark or Whiteboard, which turns the board into a whiteboard covered in sticky notes.
|
|
122
|
+
|
|
123
|
+
## History and comments
|
|
124
|
+
|
|
125
|
+
Every change you make on the board is recorded at the bottom of the card file, with who made it and when:
|
|
126
|
+
|
|
127
|
+
```markdown
|
|
128
|
+
## Comments
|
|
129
|
+
|
|
130
|
+
### 2026-11-17T09:12:00Z anna
|
|
131
|
+
|
|
132
|
+
The session timeout is 5 minutes.
|
|
133
|
+
|
|
134
|
+
## Changelog
|
|
135
|
+
|
|
136
|
+
- 2026-11-17T09:00:00Z anna card: created
|
|
137
|
+
- 2026-11-17T09:10:00Z anna status: todo → doing
|
|
138
|
+
- 2026-11-17T09:12:00Z anna comment: added
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The card view shows comments and history separately from the card's text. Changes made directly in the file aren't recorded.
|
|
142
|
+
|
|
143
|
+
## Exporting to Statsinator
|
|
144
|
+
|
|
145
|
+
To look at the board's flow in Statsinator, export its history and import the file there:
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
npx markanban ./my-board --export stats.json
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This writes one row per status change for every card, archived ones too, then exits without starting the board. A card is identified by its file name without `.md` (`frontend/fix-login` in a lane); its type and tags come along as `issue_type` and `labels`. Only moves recorded in the history are exported, so a card that was never moved on the board is left out (the export says how many). Filtering by type or date happens in Statsinator.
|
|
152
|
+
|
|
153
|
+
## Colors
|
|
154
|
+
|
|
155
|
+
Cards get a colored edge based on their `type`. Common types have colors out of the box:
|
|
156
|
+
|
|
157
|
+
| Color | Types |
|
|
158
|
+
| --- | --- |
|
|
159
|
+
| red | bug, defect, incident |
|
|
160
|
+
| orange | epic |
|
|
161
|
+
| yellow | spike, research |
|
|
162
|
+
| green | feature, story |
|
|
163
|
+
| blue | improvement, enhancement |
|
|
164
|
+
| teal | docs, documentation |
|
|
165
|
+
| purple | design |
|
|
166
|
+
| grey | task, chore |
|
|
167
|
+
|
|
168
|
+
Other types have no color until you add them to `.markanban.yml` (below).
|
|
169
|
+
|
|
170
|
+
## Settings: `.markanban.yml`
|
|
171
|
+
|
|
172
|
+
Optional. It lives in the board folder and is created for you the first time you reorder columns, add a column, or empty one by moving or archiving its last card.
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
columns: [backlog, todo, doing, review, done] # column order
|
|
176
|
+
noStatusColumn: Inbox # name of the "No status" column
|
|
177
|
+
types: # colors per type
|
|
178
|
+
incident: orange
|
|
179
|
+
ops: pink
|
|
180
|
+
wip: # WIP limit per column
|
|
181
|
+
doing: 3
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Colors: `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `purple`, `pink`, `grey`. If something in the file is wrong, the board still works and shows a warning telling you what to fix.
|
|
185
|
+
|
|
186
|
+
## Who you are
|
|
187
|
+
|
|
188
|
+
Comments and history use your name. Markanban picks it from, in order:
|
|
189
|
+
|
|
190
|
+
1. `--user anna`
|
|
191
|
+
2. the `MARKANBAN_USER` environment variable (e.g. `export MARKANBAN_USER=anna` in your shell profile)
|
|
192
|
+
3. your computer's login name
|
|
193
|
+
|
|
194
|
+
## Attachments
|
|
195
|
+
|
|
196
|
+
A card's files live in a folder next to it with the same name: the attachments of `fix-login-bug.md` are the files in `fix-login-bug/`. Every file in that folder is an attachment, so you can also drop files in with Finder or Explorer; they show up within a few seconds. Cards with attachments show 📎 and the number of files.
|
|
197
|
+
|
|
198
|
+
- Uploading keeps the file's name. If the name is taken, the new file becomes `shot-2.png`, `shot-3.png`, and so on; nothing is ever overwritten. Files can be up to 50 MB.
|
|
199
|
+
- Uploads from the board are recorded in the history (`attachment: added shot.png`); files you add by hand aren't.
|
|
200
|
+
- Clicking an attachment opens it in a new tab. Images (png, jpg, gif, webp) show in the browser; other files download.
|
|
201
|
+
- To link a file from the card text, use its path: ``. That works in any markdown viewer.
|
|
202
|
+
- There's no remove button: delete the file from the folder.
|
|
203
|
+
|
|
204
|
+
## Sharing a board
|
|
205
|
+
|
|
206
|
+
Put the folder in a synced folder (Google Drive for desktop, Dropbox, OneDrive) or on a network share, and have each person run Markanban on their own computer, pointed at their local copy:
|
|
207
|
+
|
|
208
|
+
```sh
|
|
209
|
+
cd ~/"Library/CloudStorage/GoogleDrive-<you>/My Drive/team-board"
|
|
210
|
+
npx markanban
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Each person's changes are recorded under their own name, and other people's changes show up on your board within a few seconds of syncing.
|
|
214
|
+
|
|
215
|
+
If two people change the same card at almost the same moment, the sync service decides what happens. Dropbox and OneDrive create a conflict copy (like `card (1).md`), which shows a ⚠️ so you can sort it out. Google Drive keeps the newest version; the other one is in the file's version history in Drive.
|
|
216
|
+
|
|
217
|
+
Markanban only accepts connections from your own computer; it isn't reachable from the network.
|
|
218
|
+
|
|
219
|
+
## Limitations
|
|
220
|
+
|
|
221
|
+
- Replay shows every card in the lane it's in now; moves between lanes aren't replayed.
|
|
222
|
+
- Card text and comments are shown as plain text; markdown isn't rendered yet.
|
|
223
|
+
- Changes made outside the board (in an editor or by sync) aren't recorded in the history, so Replay can't show them: such a card jumps to where it is now at the end. Stats leaves such cards out of lead time and throughput, and says how many.
|
|
224
|
+
- A card file Markanban can't read (for example, no permission) is left out and a warning names it.
|
|
225
|
+
|
|
226
|
+
## Contributing
|
|
227
|
+
|
|
228
|
+
Design and behaviour are described in [`SPEC.md`](SPEC.md). Development conventions are in [`AGENTS.md`](AGENTS.md).
|
|
229
|
+
|
|
230
|
+
```sh
|
|
231
|
+
npm install
|
|
232
|
+
git config core.hooksPath .githooks # once: runs the checks before every push
|
|
233
|
+
npm run check # lint, type check and tests
|
|
234
|
+
npm start -- ./some-board
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Changes go straight to `main`. The same `npm run check` runs on GitHub for every push.
|
|
238
|
+
|
|
239
|
+
To see Replay in action, generate a demo board: the story of how Markanban itself was built, about 20 cards dated over the last three weeks and sorted into three [swimlanes](#swimlanes). It has [WIP limits](#wip-limits) too: watch doing and review turn red when the story goes over them.
|
|
240
|
+
|
|
241
|
+
```sh
|
|
242
|
+
npm run demo -- ./demo-board # needs a new or empty folder
|
|
243
|
+
npm start -- ./demo-board # then press ▶ Replay
|
|
244
|
+
```
|
package/dist/board.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Board-level rules: column ordering, type colors and the optional .markanban.yml file.
|
|
2
|
+
//
|
|
3
|
+
// Config problems never break the board: the broken part is skipped, the default is used,
|
|
4
|
+
// and a warning (with valid values) is returned for the UI to show.
|
|
5
|
+
import { parseDocument } from 'yaml';
|
|
6
|
+
export const CONFIG_FILE = '.markanban.yml';
|
|
7
|
+
const COMMON = ['backlog', 'todo', 'ready', 'doing', 'in progress', 'review', 'done'];
|
|
8
|
+
// Color names, not hex: each theme defines its own shade (--type-<name>) so colors fit light/dark/etc.
|
|
9
|
+
const PALETTE = ['red', 'orange', 'yellow', 'green', 'teal', 'blue', 'purple', 'pink', 'grey'];
|
|
10
|
+
const BUILT_IN = {
|
|
11
|
+
bug: 'red', defect: 'red', incident: 'red',
|
|
12
|
+
epic: 'orange',
|
|
13
|
+
spike: 'yellow', research: 'yellow',
|
|
14
|
+
feature: 'green', story: 'green',
|
|
15
|
+
improvement: 'blue', enhancement: 'blue',
|
|
16
|
+
docs: 'teal', documentation: 'teal',
|
|
17
|
+
design: 'purple',
|
|
18
|
+
task: 'grey', chore: 'grey',
|
|
19
|
+
};
|
|
20
|
+
const norm = (t) => t.trim().toLowerCase();
|
|
21
|
+
const isColor = (c) => PALETTE.includes(c);
|
|
22
|
+
export function parseConfig(text) {
|
|
23
|
+
const config = { columns: [], noStatusColumn: 'No status', types: {}, wip: {}, warnings: [] };
|
|
24
|
+
const warn = (msg) => config.warnings.push(`${CONFIG_FILE}: ${msg}`);
|
|
25
|
+
const doc = parseDocument(text);
|
|
26
|
+
if (doc.errors.length) {
|
|
27
|
+
warn(`not valid YAML, using defaults (${doc.errors[0].message.split('\n')[0]})`);
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
const raw = doc.toJS();
|
|
31
|
+
if (raw == null)
|
|
32
|
+
return config;
|
|
33
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
34
|
+
warn('should be a map of settings, using defaults. Valid keys: columns, noStatusColumn, types, wip');
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
// A key with no value (`types:`, half-written) means the default, silently: it can't break anything.
|
|
38
|
+
const data = Object.fromEntries(Object.entries(raw).filter(([, v]) => v !== null));
|
|
39
|
+
if (data.columns !== undefined) {
|
|
40
|
+
if (Array.isArray(data.columns)) {
|
|
41
|
+
for (const col of data.columns) {
|
|
42
|
+
if (col == null || typeof col === 'object')
|
|
43
|
+
warn('a column must be text, e.g. columns: [todo, doing, done]; skipped one entry');
|
|
44
|
+
else
|
|
45
|
+
config.columns.push(String(col));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
warn('columns must be a list, e.g. columns: [todo, doing, done]');
|
|
50
|
+
}
|
|
51
|
+
if (data.noStatusColumn !== undefined) {
|
|
52
|
+
const v = data.noStatusColumn;
|
|
53
|
+
if (typeof v === 'string' && v.trim())
|
|
54
|
+
config.noStatusColumn = v;
|
|
55
|
+
else
|
|
56
|
+
warn('noStatusColumn must be text, e.g. noStatusColumn: Inbox');
|
|
57
|
+
}
|
|
58
|
+
if (data.types !== undefined) {
|
|
59
|
+
const types = data.types;
|
|
60
|
+
if (types === null || typeof types !== 'object' || Array.isArray(types)) {
|
|
61
|
+
warn('types must be a map of type to color, e.g. types: { bug: red }');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
for (const [type, value] of Object.entries(types)) {
|
|
65
|
+
const color = String(value).trim().toLowerCase();
|
|
66
|
+
if (isColor(color))
|
|
67
|
+
config.types[norm(type)] = color;
|
|
68
|
+
else
|
|
69
|
+
warn(`unknown color "${value}" for type "${type}". Use one of: ${PALETTE.join(', ')}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (data.wip !== undefined) {
|
|
74
|
+
const wip = data.wip;
|
|
75
|
+
if (wip === null || typeof wip !== 'object' || Array.isArray(wip)) {
|
|
76
|
+
warn('wip must be a map of column to limit, e.g. wip: { doing: 3 }');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
for (const [column, value] of Object.entries(wip)) {
|
|
80
|
+
if (Number.isInteger(value) && value >= 1)
|
|
81
|
+
config.wip[norm(column)] = value;
|
|
82
|
+
else
|
|
83
|
+
warn(`wip for "${column}" must be a whole number of 1 or more, e.g. wip: { doing: 3 }`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
}
|
|
89
|
+
/** A column's WIP limit, found by its label as shown on the board (case and spaces ignored). */
|
|
90
|
+
export function wipLimit(label, wip) {
|
|
91
|
+
return Object.hasOwn(wip, norm(label)) ? wip[norm(label)] : null;
|
|
92
|
+
}
|
|
93
|
+
/** Configured color first, then the built-in list; unknown or missing type gets no color. */
|
|
94
|
+
export function typeColor(type, configured) {
|
|
95
|
+
if (!type)
|
|
96
|
+
return null;
|
|
97
|
+
const t = norm(type);
|
|
98
|
+
return configured[t] ?? BUILT_IN[t] ?? null;
|
|
99
|
+
}
|
|
100
|
+
export function setConfigColumns(text, columns) {
|
|
101
|
+
const doc = parseDocument(text);
|
|
102
|
+
if (doc.errors.length)
|
|
103
|
+
throw new Error(`${CONFIG_FILE} is not valid YAML`);
|
|
104
|
+
const node = doc.createNode(columns);
|
|
105
|
+
node.flow = true;
|
|
106
|
+
doc.set('columns', node);
|
|
107
|
+
return String(doc);
|
|
108
|
+
}
|
|
109
|
+
/** Configured columns first (even if empty), then known statuses in the common order, then alphabetical. */
|
|
110
|
+
export function orderColumns(statuses, configured) {
|
|
111
|
+
const rank = (s) => {
|
|
112
|
+
const i = COMMON.indexOf(s.toLowerCase());
|
|
113
|
+
return i < 0 ? COMMON.length : i;
|
|
114
|
+
};
|
|
115
|
+
const rest = [...new Set(statuses)].filter((s) => !configured.includes(s))
|
|
116
|
+
.sort((a, b) => rank(a) - rank(b) || a.localeCompare(b));
|
|
117
|
+
return [...new Set(configured), ...rest];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Swimlanes: top-level cards first (an unnamed lane, only while it has active cards), then lane folders in
|
|
121
|
+
* natural, case-insensitive order. Archived cards keep a folder lane alive. `[null]` alone is a plain board.
|
|
122
|
+
*/
|
|
123
|
+
export function orderLanes(cards) {
|
|
124
|
+
const named = [...new Set(cards.flatMap((c) => (c.lane === null ? [] : [c.lane])))]
|
|
125
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }) || a.localeCompare(b));
|
|
126
|
+
return [...(cards.some((c) => c.lane === null && !c.archived) || !named.length ? [null] : []), ...named];
|
|
127
|
+
}
|
|
128
|
+
// ---- Card order within a column (priority: top = most important) ----
|
|
129
|
+
const STEP = 1000;
|
|
130
|
+
const MIN_GAP = 0.001;
|
|
131
|
+
/** Ranked cards by number, then unranked cards oldest first. */
|
|
132
|
+
export function rankOrder(a, b) {
|
|
133
|
+
if (a.rank !== null && b.rank !== null)
|
|
134
|
+
return a.rank - b.rank || a.name.localeCompare(b.name);
|
|
135
|
+
if (a.rank !== null)
|
|
136
|
+
return -1;
|
|
137
|
+
if (b.rank !== null)
|
|
138
|
+
return 1;
|
|
139
|
+
return a.created.localeCompare(b.created) || a.name.localeCompare(b.name);
|
|
140
|
+
}
|
|
141
|
+
const tidy = (n) => Math.round(n * 1e6) / 1e6;
|
|
142
|
+
/**
|
|
143
|
+
* Where a card lands when placed above `before` (or at the bottom when null) in `column`
|
|
144
|
+
* (sorted with rankOrder, without the card being moved). Returns the moved card's new rank,
|
|
145
|
+
* plus rank updates for other cards: unranked cards above the drop point, or the whole column
|
|
146
|
+
* when the gap has run out.
|
|
147
|
+
*/
|
|
148
|
+
export function placeCard(column, before) {
|
|
149
|
+
const at = before === null ? column.length : column.findIndex((c) => c.name === before);
|
|
150
|
+
if (at < 0)
|
|
151
|
+
throw new Error(`No card "${before}" in that column`);
|
|
152
|
+
const updates = new Map();
|
|
153
|
+
// Cards above the drop point need a rank so the moved card can sort after them.
|
|
154
|
+
let above = null;
|
|
155
|
+
for (const c of column.slice(0, at)) {
|
|
156
|
+
const rank = c.rank ?? (above ?? 0) + STEP;
|
|
157
|
+
if (c.rank === null)
|
|
158
|
+
updates.set(c.name, rank);
|
|
159
|
+
above = rank;
|
|
160
|
+
}
|
|
161
|
+
const below = column[at]?.rank ?? null; // an unranked card below is no upper bound
|
|
162
|
+
let rank;
|
|
163
|
+
if (below === null)
|
|
164
|
+
rank = (above ?? 0) + STEP;
|
|
165
|
+
else if (above === null)
|
|
166
|
+
rank = below - STEP;
|
|
167
|
+
else if (below - above >= MIN_GAP * 2)
|
|
168
|
+
rank = tidy((above + below) / 2);
|
|
169
|
+
else {
|
|
170
|
+
// Gap used up: renumber this column (ranked cards and the moved one) in clean steps.
|
|
171
|
+
const order = [...column.slice(0, at), null, ...column.slice(at).filter((c) => c.rank !== null)];
|
|
172
|
+
rank = 0;
|
|
173
|
+
order.forEach((c, i) => {
|
|
174
|
+
const r = (i + 1) * STEP;
|
|
175
|
+
if (c === null)
|
|
176
|
+
rank = r; // the moved card
|
|
177
|
+
else if (c.rank !== r)
|
|
178
|
+
updates.set(c.name, r);
|
|
179
|
+
else
|
|
180
|
+
updates.delete(c.name);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return { rank, updates: [...updates].map(([name, r]) => ({ name, rank: r })) };
|
|
184
|
+
}
|
|
185
|
+
// The name never contains ": ", so a heading or file name that mentions "status: a → b" can't pass for a change.
|
|
186
|
+
const CHANGE = /^(\S+) (?:(?!: ).)+? (status|archived): (.*?) → (.*)$/;
|
|
187
|
+
const CREATED = /^(\S+) .+? card: created$/;
|
|
188
|
+
const logValue = (v) => (v === '(none)' ? null : v);
|
|
189
|
+
/**
|
|
190
|
+
* A card's states over time. It appears at `card: created` (else `created`, which is the file
|
|
191
|
+
* birthtime when missing), in the `from` of its first status change. Only status and archive are
|
|
192
|
+
* replayed. If the log doesn't end in the card's current state (edited outside the UI), it
|
|
193
|
+
* jumps there at `end`.
|
|
194
|
+
*
|
|
195
|
+
* `logged` marks the steps the changelog vouches for: the first step only when it comes from
|
|
196
|
+
* `card: created`, and never the jump at `end`. Stats measures only logged moves.
|
|
197
|
+
*/
|
|
198
|
+
export function cardTimeline(card, end) {
|
|
199
|
+
let appear = Date.parse(card.created);
|
|
200
|
+
let createdLogged = false;
|
|
201
|
+
const changes = [];
|
|
202
|
+
for (const line of card.history) {
|
|
203
|
+
const m = CHANGE.exec(line);
|
|
204
|
+
const at = Date.parse((m ?? CREATED.exec(line))?.[1] ?? '');
|
|
205
|
+
if (Number.isNaN(at))
|
|
206
|
+
continue;
|
|
207
|
+
if (m)
|
|
208
|
+
changes.push({ at, field: m[2], from: logValue(m[3]), to: logValue(m[4]) });
|
|
209
|
+
else {
|
|
210
|
+
appear = at;
|
|
211
|
+
createdLogged = true;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
changes.sort((a, b) => a.at - b.at);
|
|
215
|
+
const first = (field) => changes.find((c) => c.field === field);
|
|
216
|
+
let state = { status: first('status') ? first('status').from : card.status, archived: first('archived')?.from != null };
|
|
217
|
+
const start = Math.min(Number.isNaN(appear) ? end : appear, changes[0]?.at ?? end);
|
|
218
|
+
const steps = [{ at: start, ...state }];
|
|
219
|
+
// A logged change dated before `card: created` comes first, so the start is then a guess.
|
|
220
|
+
const logged = [createdLogged && start === appear];
|
|
221
|
+
for (const c of changes) {
|
|
222
|
+
state = c.field === 'status' ? { ...state, status: c.to } : { ...state, archived: c.to !== null };
|
|
223
|
+
steps.push({ at: c.at, ...state });
|
|
224
|
+
logged.push(true);
|
|
225
|
+
}
|
|
226
|
+
const now = { status: card.status, archived: card.archived !== null };
|
|
227
|
+
if (state.status !== now.status || state.archived !== now.archived) {
|
|
228
|
+
steps.push({ at: end, ...now });
|
|
229
|
+
logged.push(false);
|
|
230
|
+
}
|
|
231
|
+
return { steps, logged };
|
|
232
|
+
}
|
|
233
|
+
/** Everything the browser needs to play the board back from the first event to `end`. */
|
|
234
|
+
export function replay(cards, current, config, end) {
|
|
235
|
+
const steps = Object.fromEntries(cards.map((c) => [c.name, cardTimeline(c, end).steps]));
|
|
236
|
+
const all = Object.values(steps).flat();
|
|
237
|
+
const statuses = all.flatMap((s) => (s.status === null ? [] : [s.status]));
|
|
238
|
+
const keys = orderColumns([...statuses, ...current.filter((k) => k !== null)], config.columns);
|
|
239
|
+
if (current.includes(null) || all.some((s) => s.status === null))
|
|
240
|
+
keys.unshift(null);
|
|
241
|
+
return {
|
|
242
|
+
start: Math.min(end, ...all.map((s) => s.at)),
|
|
243
|
+
end,
|
|
244
|
+
columns: keys.map((key) => {
|
|
245
|
+
const label = key ?? config.noStatusColumn;
|
|
246
|
+
return { key, label, current: current.includes(key), limit: wipLimit(label, config.wip) };
|
|
247
|
+
}),
|
|
248
|
+
steps,
|
|
249
|
+
};
|
|
250
|
+
}
|