@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.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -2
  3. package/boards/actions/create-board.d.ts +1 -0
  4. package/boards/actions/create-board.js +47 -0
  5. package/boards/actions/create-card.d.ts +1 -0
  6. package/boards/actions/create-card.js +83 -0
  7. package/boards/actions/delete-board.d.ts +1 -0
  8. package/boards/actions/delete-board.js +30 -0
  9. package/boards/actions/delete-card.d.ts +1 -0
  10. package/boards/actions/delete-card.js +24 -0
  11. package/boards/actions/move-card.d.ts +1 -0
  12. package/boards/actions/move-card.js +85 -0
  13. package/boards/actions/update-board.d.ts +1 -0
  14. package/boards/actions/update-board.js +110 -0
  15. package/boards/actions/update-card.d.ts +1 -0
  16. package/boards/actions/update-card.js +67 -0
  17. package/boards/collections/board.d.ts +71 -0
  18. package/boards/collections/board.js +32 -0
  19. package/boards/collections/card.d.ts +74 -0
  20. package/boards/collections/card.js +29 -0
  21. package/boards/contract.d.ts +67 -0
  22. package/boards/contract.js +20 -0
  23. package/boards/mod.d.ts +34 -0
  24. package/boards/mod.js +72 -0
  25. package/boards/resources/tools.d.ts +2 -0
  26. package/boards/resources/tools.js +414 -0
  27. package/boards/shared/columns.d.ts +39 -0
  28. package/boards/shared/columns.js +88 -0
  29. package/boards/shared/dates.d.ts +11 -0
  30. package/boards/shared/dates.js +22 -0
  31. package/boards/shared/errors.d.ts +24 -0
  32. package/boards/shared/errors.js +20 -0
  33. package/boards/shared/fields.d.ts +65 -0
  34. package/boards/shared/fields.js +44 -0
  35. package/boards/shared/load.d.ts +22 -0
  36. package/boards/shared/load.js +32 -0
  37. package/boards/shared/order.d.ts +30 -0
  38. package/boards/shared/order.js +47 -0
  39. package/boards/shared/people.d.ts +30 -0
  40. package/boards/shared/people.js +87 -0
  41. package/boards/shared/said.d.ts +28 -0
  42. package/boards/shared/said.js +30 -0
  43. package/boards/views/web/board-head.d.ts +62 -0
  44. package/boards/views/web/board-head.js +170 -0
  45. package/boards/views/web/board-page.d.ts +17 -0
  46. package/boards/views/web/board-page.js +97 -0
  47. package/boards/views/web/board-view.d.ts +40 -0
  48. package/boards/views/web/board-view.js +341 -0
  49. package/boards/views/web/boards-tab.d.ts +13 -0
  50. package/boards/views/web/boards-tab.js +109 -0
  51. package/boards/views/web/card-sheet.d.ts +47 -0
  52. package/boards/views/web/card-sheet.js +314 -0
  53. package/boards/views/web/card-tile.d.ts +29 -0
  54. package/boards/views/web/card-tile.js +20 -0
  55. package/boards/views/web/column.d.ts +38 -0
  56. package/boards/views/web/column.js +171 -0
  57. package/boards/views/web/drag.d.ts +36 -0
  58. package/boards/views/web/drag.js +276 -0
  59. package/boards/views/web/glyphs.d.ts +29 -0
  60. package/boards/views/web/glyphs.js +25 -0
  61. package/boards/views/web/load.d.ts +32 -0
  62. package/boards/views/web/load.js +33 -0
  63. package/boards/views/web/palette.d.ts +15 -0
  64. package/boards/views/web/palette.js +180 -0
  65. package/boards/views/web/pickers.d.ts +45 -0
  66. package/boards/views/web/pickers.js +83 -0
  67. package/boards/views/web/shown.d.ts +77 -0
  68. package/boards/views/web/shown.js +136 -0
  69. package/boards/views/web/step.d.ts +13 -0
  70. package/boards/views/web/step.js +41 -0
  71. package/boards/views/web/style.d.ts +10 -0
  72. package/boards/views/web/style.js +380 -0
  73. package/boards/views/web/toolbar.d.ts +21 -0
  74. package/boards/views/web/toolbar.js +39 -0
  75. package/boards/web.d.ts +26 -0
  76. package/boards/web.js +52 -0
  77. package/contract.d.ts +7 -0
  78. package/contract.js +7 -0
  79. package/documents/actions/create.d.ts +1 -0
  80. package/documents/actions/create.js +28 -0
  81. package/documents/actions/delete.d.ts +1 -0
  82. package/documents/actions/delete.js +32 -0
  83. package/documents/actions/presence.d.ts +1 -0
  84. package/documents/actions/presence.js +45 -0
  85. package/documents/actions/rename.d.ts +1 -0
  86. package/documents/actions/rename.js +33 -0
  87. package/documents/actions/restore.d.ts +1 -0
  88. package/documents/actions/restore.js +39 -0
  89. package/documents/actions/save.d.ts +1 -0
  90. package/documents/actions/save.js +78 -0
  91. package/documents/collections/document-presence.d.ts +79 -0
  92. package/documents/collections/document-presence.js +25 -0
  93. package/documents/collections/document-version.d.ts +166 -0
  94. package/documents/collections/document-version.js +60 -0
  95. package/documents/collections/document.d.ts +131 -0
  96. package/documents/collections/document.js +72 -0
  97. package/documents/contract.d.ts +17 -0
  98. package/documents/contract.js +1 -0
  99. package/documents/mod.d.ts +38 -0
  100. package/documents/mod.js +75 -0
  101. package/documents/resources/tools.d.ts +2 -0
  102. package/documents/resources/tools.js +253 -0
  103. package/documents/shared/diff.d.ts +37 -0
  104. package/documents/shared/diff.js +148 -0
  105. package/documents/shared/merge.d.ts +29 -0
  106. package/documents/shared/merge.js +120 -0
  107. package/documents/shared/presence.d.ts +7 -0
  108. package/documents/shared/presence.js +7 -0
  109. package/documents/shared/text.d.ts +36 -0
  110. package/documents/shared/text.js +67 -0
  111. package/documents/shared/who.d.ts +23 -0
  112. package/documents/shared/who.js +39 -0
  113. package/documents/shared/write.d.ts +54 -0
  114. package/documents/shared/write.js +123 -0
  115. package/documents/views/web/changes.d.ts +22 -0
  116. package/documents/views/web/changes.js +57 -0
  117. package/documents/views/web/conflict.d.ts +38 -0
  118. package/documents/views/web/conflict.js +96 -0
  119. package/documents/views/web/draft.d.ts +18 -0
  120. package/documents/views/web/draft.js +32 -0
  121. package/documents/views/web/editor.d.ts +57 -0
  122. package/documents/views/web/editor.js +268 -0
  123. package/documents/views/web/format.d.ts +56 -0
  124. package/documents/views/web/format.js +245 -0
  125. package/documents/views/web/history.d.ts +23 -0
  126. package/documents/views/web/history.js +118 -0
  127. package/documents/views/web/list.d.ts +37 -0
  128. package/documents/views/web/list.js +211 -0
  129. package/documents/views/web/page.d.ts +35 -0
  130. package/documents/views/web/page.js +416 -0
  131. package/documents/views/web/palette.d.ts +16 -0
  132. package/documents/views/web/palette.js +168 -0
  133. package/documents/views/web/people.d.ts +60 -0
  134. package/documents/views/web/people.js +63 -0
  135. package/documents/views/web/presence.d.ts +30 -0
  136. package/documents/views/web/presence.js +75 -0
  137. package/documents/views/web/step.d.ts +25 -0
  138. package/documents/views/web/step.js +81 -0
  139. package/documents/views/web/style.d.ts +7 -0
  140. package/documents/views/web/style.js +266 -0
  141. package/documents/web.d.ts +18 -0
  142. package/documents/web.js +46 -0
  143. package/mod.d.ts +18 -0
  144. package/mod.js +18 -0
  145. package/package.json +61 -4
  146. package/web.d.ts +13 -0
  147. package/web.js +13 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Dragging cards with pointer events, so a mouse, a pen and a finger all
3
+ * work, with no library. A mouse drag starts once the pointer moves a few
4
+ * pixels; a finger's after a short press that stays put, so a swipe still
5
+ * scrolls the board. The card lifts into a copy that follows the pointer,
6
+ * and a slot opens where it would land: the column under the pointer (or
7
+ * the nearest), above the first card whose middle is below it. Near an edge
8
+ * the columns scroll sideways, a column's cards up and down, and the page
9
+ * too. Letting go settles the copy into the slot, then hands the move over
10
+ * (`onDrop`); Escape puts it back. The board shows the slot (`preview`).
11
+ *
12
+ * The board marks its parts: the row of columns `data-scroller`, a column
13
+ * `data-column`, its cards' list `data-list="<column id>"` (positioned, so
14
+ * cards measure from it), a card `data-card="<id>"`, the slot `data-slot`.
15
+ */
16
+ import { type PointerEvent as ReactPointerEvent, type RefObject } from "react";
17
+ /** Where a lifted card would land: its column, and its place among the cards shown there. */
18
+ export type Preview = {
19
+ card: string;
20
+ column: string;
21
+ index: number;
22
+ /** The slot's height: the card's own. */
23
+ height: number;
24
+ by: "pointer" | "keyboard";
25
+ };
26
+ export declare function useCardDrag({ root, enabled, onDrop }: {
27
+ root: RefObject<HTMLElement | null>;
28
+ enabled: boolean;
29
+ /** The card let go of, its column, and its place among the cards shown there (`Infinity`: the bottom). */
30
+ onDrop(card: string, column: string, index: number): void;
31
+ }): {
32
+ preview: Preview | undefined;
33
+ press: (event: ReactPointerEvent<HTMLElement>, card: string, column: string) => void;
34
+ /** Whether a drag just ended: the click that ends it doesn't open the card. */
35
+ justDragged: () => boolean;
36
+ };
@@ -0,0 +1,276 @@
1
+ /**
2
+ * Dragging cards with pointer events, so a mouse, a pen and a finger all
3
+ * work, with no library. A mouse drag starts once the pointer moves a few
4
+ * pixels; a finger's after a short press that stays put, so a swipe still
5
+ * scrolls the board. The card lifts into a copy that follows the pointer,
6
+ * and a slot opens where it would land: the column under the pointer (or
7
+ * the nearest), above the first card whose middle is below it. Near an edge
8
+ * the columns scroll sideways, a column's cards up and down, and the page
9
+ * too. Letting go settles the copy into the slot, then hands the move over
10
+ * (`onDrop`); Escape puts it back. The board shows the slot (`preview`).
11
+ *
12
+ * The board marks its parts: the row of columns `data-scroller`, a column
13
+ * `data-column`, its cards' list `data-list="<column id>"` (positioned, so
14
+ * cards measure from it), a card `data-card="<id>"`, the slot `data-slot`.
15
+ */
16
+ import { useEffect, useRef, useState, } from "react";
17
+ const MOUSE_SLOP = 4;
18
+ const TOUCH_SLOP = 10;
19
+ const TOUCH_DELAY = 220;
20
+ /** How near an edge scrolling starts, and how fast it goes there. */
21
+ const EDGE = 64;
22
+ const SPEED = 20;
23
+ const SETTLE_MS = 170;
24
+ /** The column under (or nearest) a point, and the place there: above the first card whose middle is below it. */
25
+ function targetAt(root, x, y) {
26
+ const lists = [...root.querySelectorAll("[data-list]")];
27
+ let best;
28
+ let nearest = Infinity;
29
+ for (const list of lists) {
30
+ const box = (list.closest("[data-column]") ?? list).getBoundingClientRect();
31
+ const dx = x < box.left ? box.left - x : x > box.right ? x - box.right : 0;
32
+ const dy = y < box.top ? box.top - y : y > box.bottom ? y - box.bottom : 0;
33
+ const distance = dx * dx + dy * dy;
34
+ if (distance < nearest) {
35
+ nearest = distance;
36
+ best = list;
37
+ }
38
+ }
39
+ if (!best)
40
+ return undefined;
41
+ const column = best.dataset.list;
42
+ if (best.dataset.folded !== undefined)
43
+ return { column, index: Infinity };
44
+ const box = best.getBoundingClientRect();
45
+ const top = box.top + best.clientTop - best.scrollTop;
46
+ // Layout positions, not where cards are drawn while they glide aside.
47
+ const cards = [...best.querySelectorAll(":scope > [data-card]:not([data-lifted])")];
48
+ const index = cards.filter((c) => top + c.offsetTop + c.offsetHeight / 2 < y).length;
49
+ return { column, index };
50
+ }
51
+ /** The nearest ancestor that scrolls up and down. */
52
+ function scrollerOf(element) {
53
+ for (let at = element?.parentElement; at; at = at.parentElement) {
54
+ const { overflowY } = getComputedStyle(at);
55
+ if (/(auto|scroll)/.test(overflowY) && at.scrollHeight > at.clientHeight)
56
+ return at;
57
+ }
58
+ return undefined;
59
+ }
60
+ /** How far to scroll this frame, at `distance` from an edge. */
61
+ const pace = (distance) => distance < EDGE ? Math.ceil(((EDGE - Math.max(distance, 0)) / EDGE) * SPEED) : 0;
62
+ export function useCardDrag({ root, enabled, onDrop }) {
63
+ const [preview, setPreview] = useState();
64
+ const latest = useRef({ enabled, onDrop });
65
+ latest.current = { enabled, onDrop };
66
+ // Made once: the listeners it adds are the ones it takes away.
67
+ const [drag] = useState(() => dragging(root, setPreview, () => latest.current));
68
+ useEffect(() => drag.finish, [drag]);
69
+ return {
70
+ preview,
71
+ press: drag.press,
72
+ /** Whether a drag just ended: the click that ends it doesn't open the card. */
73
+ justDragged: drag.justDragged,
74
+ };
75
+ }
76
+ /** The drag's machinery, made once per board: its state is refs, not React's. */
77
+ function dragging(root, setPreview, current) {
78
+ let pressed;
79
+ let shown;
80
+ let frame;
81
+ let ended = 0;
82
+ const show = (next) => {
83
+ const was = shown;
84
+ if (was === next ||
85
+ (was && next && was.card === next.card && was.column === next.column &&
86
+ was.index === next.index))
87
+ return;
88
+ shown = next;
89
+ setPreview(next);
90
+ };
91
+ const follow = (p, x, y) => {
92
+ p.at = { x, y };
93
+ if (p.ghost)
94
+ p.ghost.style.translate = `${x - p.dx}px ${y - p.dy}px`;
95
+ const target = root.current ? targetAt(root.current, x, y) : undefined;
96
+ if (target)
97
+ show({ ...target, card: p.card, height: p.height, by: "pointer" });
98
+ };
99
+ /** Scrolls what the pointer is near the edge of, every frame while dragging. */
100
+ const scroll = () => {
101
+ const p = pressed;
102
+ const board = root.current;
103
+ if (!p?.started || !board)
104
+ return;
105
+ const { x, y } = p.at;
106
+ let moved = false;
107
+ const row = board.querySelector("[data-scroller]");
108
+ if (row && row.scrollWidth > row.clientWidth) {
109
+ const box = row.getBoundingClientRect();
110
+ const by = pace(x - box.left) ? -pace(x - box.left) : pace(box.right - x);
111
+ if (by && y > box.top - EDGE && y < box.bottom + EDGE) {
112
+ const before = row.scrollLeft;
113
+ row.scrollLeft += by;
114
+ moved ||= row.scrollLeft !== before;
115
+ }
116
+ }
117
+ const list = shown
118
+ ? board.querySelector(`[data-list="${CSS.escape(shown.column)}"]`)
119
+ : null;
120
+ for (const area of [list, scrollerOf(board)]) {
121
+ if (!area || area.scrollHeight <= area.clientHeight)
122
+ continue;
123
+ const box = area.getBoundingClientRect();
124
+ const top = Math.max(box.top, 0);
125
+ const bottom = Math.min(box.bottom, innerHeight);
126
+ const by = pace(y - top) ? -pace(y - top) : pace(bottom - y);
127
+ if (!by)
128
+ continue;
129
+ const before = area.scrollTop;
130
+ area.scrollTop += by;
131
+ if (area.scrollTop !== before) {
132
+ moved = true;
133
+ break;
134
+ }
135
+ }
136
+ if (moved)
137
+ follow(p, x, y);
138
+ frame = requestAnimationFrame(scroll);
139
+ };
140
+ const lift = (p) => {
141
+ p.started = true;
142
+ const box = p.element.getBoundingClientRect();
143
+ p.dx = p.x - box.left;
144
+ p.dy = p.y - box.top;
145
+ p.height = box.height;
146
+ const ghost = p.element.cloneNode(true);
147
+ ghost.removeAttribute("data-card");
148
+ for (const named of [ghost, ...ghost.querySelectorAll("[id]")])
149
+ named.removeAttribute("id");
150
+ ghost.setAttribute("aria-hidden", "true");
151
+ ghost.classList.add("board-ghost");
152
+ Object.assign(ghost.style, {
153
+ width: `${box.width}px`,
154
+ height: `${box.height}px`,
155
+ translate: `${box.left}px ${box.top}px`,
156
+ });
157
+ document.body.append(ghost);
158
+ p.ghost = ghost;
159
+ document.documentElement.dataset.boardDragging = "";
160
+ if (p.touch)
161
+ navigator.vibrate?.(8);
162
+ follow(p, p.x, p.y);
163
+ frame = requestAnimationFrame(scroll);
164
+ };
165
+ const finish = () => {
166
+ const p = pressed;
167
+ if (p?.timer)
168
+ clearTimeout(p.timer);
169
+ if (frame !== undefined)
170
+ cancelAnimationFrame(frame);
171
+ frame = undefined;
172
+ p?.ghost?.remove();
173
+ if (p?.started)
174
+ ended = performance.now();
175
+ pressed = undefined;
176
+ delete document.documentElement.dataset.boardDragging;
177
+ removeEventListener("pointermove", moved);
178
+ removeEventListener("pointerup", released);
179
+ removeEventListener("pointercancel", cancelled);
180
+ removeEventListener("keydown", escaped, true);
181
+ document.removeEventListener("touchmove", held);
182
+ show(undefined);
183
+ };
184
+ function moved(event) {
185
+ const p = pressed;
186
+ if (!p || event.pointerId !== p.pointer)
187
+ return;
188
+ if (!p.started) {
189
+ const far = Math.hypot(event.clientX - p.x, event.clientY - p.y);
190
+ // A finger that moves before the press settles is scrolling, not dragging.
191
+ if (p.touch) {
192
+ if (far > TOUCH_SLOP)
193
+ finish();
194
+ return;
195
+ }
196
+ if (far < MOUSE_SLOP)
197
+ return;
198
+ lift(p);
199
+ }
200
+ event.preventDefault();
201
+ follow(p, event.clientX, event.clientY);
202
+ }
203
+ function released(event) {
204
+ const p = pressed;
205
+ if (!p || event.pointerId !== p.pointer)
206
+ return;
207
+ if (!p.started)
208
+ return finish();
209
+ follow(p, event.clientX, event.clientY);
210
+ const target = shown;
211
+ const slot = root.current?.querySelector("[data-slot]");
212
+ const ghost = p.ghost;
213
+ removeEventListener("pointermove", moved);
214
+ if (!target || !slot || !ghost || matchMedia("(prefers-reduced-motion: reduce)").matches) {
215
+ if (target)
216
+ current().onDrop(p.card, target.column, target.index);
217
+ return finish();
218
+ }
219
+ // Settle into the slot, then hand the move over.
220
+ const box = slot.getBoundingClientRect();
221
+ ghost.classList.add("board-ghost-settling");
222
+ ghost.style.translate = `${box.left}px ${box.top}px`;
223
+ ghost.style.width = `${box.width}px`;
224
+ p.timer = setTimeout(() => {
225
+ current().onDrop(p.card, target.column, target.index);
226
+ finish();
227
+ }, SETTLE_MS);
228
+ }
229
+ function cancelled(event) {
230
+ if (pressed && event.pointerId === pressed.pointer)
231
+ finish();
232
+ }
233
+ function escaped(event) {
234
+ if (event.key !== "Escape" || !pressed?.started)
235
+ return;
236
+ event.preventDefault();
237
+ event.stopPropagation();
238
+ finish();
239
+ }
240
+ // While a finger drags, the page mustn't scroll under it.
241
+ function held(event) {
242
+ if (pressed?.started && event.cancelable)
243
+ event.preventDefault();
244
+ }
245
+ /** On a card's pointerdown: starts watching for a drag. */
246
+ const press = (event, card, column) => {
247
+ if (!current().enabled || pressed || event.button !== 0 || !event.isPrimary)
248
+ return;
249
+ if (event.target.closest("[data-no-drag], input, textarea, select, a"))
250
+ return;
251
+ const p = {
252
+ card,
253
+ column,
254
+ pointer: event.pointerId,
255
+ touch: event.pointerType !== "mouse",
256
+ x: event.clientX,
257
+ y: event.clientY,
258
+ element: event.currentTarget,
259
+ started: false,
260
+ dx: 0,
261
+ dy: 0,
262
+ height: 0,
263
+ at: { x: event.clientX, y: event.clientY },
264
+ };
265
+ pressed = p;
266
+ addEventListener("pointermove", moved, { passive: false });
267
+ addEventListener("pointerup", released);
268
+ addEventListener("pointercancel", cancelled);
269
+ addEventListener("keydown", escaped, true);
270
+ if (p.touch) {
271
+ document.addEventListener("touchmove", held, { passive: false });
272
+ p.timer = setTimeout(() => pressed === p && lift(p), TOUCH_DELAY);
273
+ }
274
+ };
275
+ return { press, finish, justDragged: () => performance.now() - ended < 400 };
276
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Glyphs boards draw that the toolkit's icons don't have yet: a board, a
3
+ * calendar, a label, a description's lines, a grip, and each stage of work
4
+ * (Backlog's dashed ring, To do's ring, Doing half full, In review nearly
5
+ * full, Blocked crossed, Done checked). Line glyphs on the toolkit's 24-pixel
6
+ * grid, in the text's colour; decorative, so said beside them.
7
+ */
8
+ import type { ReactNode } from "react";
9
+ import type { Stage } from "../../shared/columns.js";
10
+ declare const PATHS: {
11
+ readonly board: "M4 4h16a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1zM9 4v16M15 4v16";
12
+ readonly calendar: "M5 5h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM3 10h18M8 3v4M16 3v4";
13
+ readonly label: "M3 12.6V4a1 1 0 0 1 1-1h8.6a1 1 0 0 1 .7.3l7.4 7.4a1 1 0 0 1 0 1.4l-8.6 8.6a1 1 0 0 1-1.4 0L3.3 13.3a1 1 0 0 1-.3-.7zM8 8h.01";
14
+ readonly lines: "M4 6h16M4 11h16M4 16h10";
15
+ readonly grip: "M9 6h.01M15 6h.01M9 12h.01M15 12h.01M9 18h.01M15 18h.01";
16
+ readonly columns: "M4 4h4v16H4zM10 4h4v10h-4zM16 4h4v13h-4z";
17
+ };
18
+ export type GlyphName = keyof typeof PATHS;
19
+ export declare function Glyph({ name, size, className }: {
20
+ name: GlyphName;
21
+ size?: number;
22
+ className?: string;
23
+ }): ReactNode;
24
+ /** A column's stage, as a ring that fills as work moves on; its colour is the stage's (style.ts). */
25
+ export declare function StageMark({ stage, size }: {
26
+ stage: Stage;
27
+ size?: number;
28
+ }): ReactNode;
29
+ export {};
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const PATHS = {
3
+ board: "M4 4h16a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1zM9 4v16M15 4v16",
4
+ calendar: "M5 5h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM3 10h18M8 3v4M16 3v4",
5
+ label: "M3 12.6V4a1 1 0 0 1 1-1h8.6a1 1 0 0 1 .7.3l7.4 7.4a1 1 0 0 1 0 1.4l-8.6 8.6a1 1 0 0 1-1.4 0L3.3 13.3a1 1 0 0 1-.3-.7zM8 8h.01",
6
+ lines: "M4 6h16M4 11h16M4 16h10",
7
+ grip: "M9 6h.01M15 6h.01M9 12h.01M15 12h.01M9 18h.01M15 18h.01",
8
+ columns: "M4 4h4v16H4zM10 4h4v10h-4zM16 4h4v13h-4z",
9
+ };
10
+ export function Glyph({ name, size = 16, className }) {
11
+ return (_jsx("svg", { className: className ? `board-glyph ${className}` : "board-glyph", width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: name === "grip" ? 3 : 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: PATHS[name] }) }));
12
+ }
13
+ /** A column's stage, as a ring that fills as work moves on; its colour is the stage's (style.ts). */
14
+ export function StageMark({ stage, size = 14 }) {
15
+ const ring = (dash) => (_jsx("circle", { cx: "8", cy: "8", r: "6", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeDasharray: dash }));
16
+ const parts = {
17
+ backlog: ring("2.2 2.2"),
18
+ todo: ring(),
19
+ doing: (_jsxs(_Fragment, { children: [ring(), _jsx("path", { d: "M8 4a4 4 0 0 1 0 8z", fill: "currentColor" })] })),
20
+ review: (_jsxs(_Fragment, { children: [ring(), _jsx("path", { d: "M8 4a4 4 0 1 1-4 4h4z", fill: "currentColor" })] })),
21
+ blocked: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "8", cy: "8", r: "6.8", fill: "currentColor" }), _jsx("path", { d: "M5.6 5.6l4.8 4.8M10.4 5.6l-4.8 4.8", stroke: "var(--background)", strokeWidth: "1.6", strokeLinecap: "round" })] })),
22
+ done: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "8", cy: "8", r: "6.8", fill: "currentColor" }), _jsx("path", { d: "M5.2 8.3l1.9 1.9 3.8-4", fill: "none", stroke: "var(--background)", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round" })] })),
23
+ };
24
+ return (_jsx("svg", { className: "board-stage", "data-stage": stage, width: size, height: size, viewBox: "0 0 16 16", "aria-hidden": "true", children: parts[stage] }));
25
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * What a board's Views read, as the person: the board, its cards, its
3
+ * space's members, what chat says of the agents among them and on its cards
4
+ * (their names and emojis), the people's names (their profiles', on its
5
+ * cards too: who made and changed them), and the spaces the person reaches (what they
6
+ * may do there, and what each is called). Each read is live: the View runs
7
+ * again when what it read changes.
8
+ */
9
+ import type { ReactNode } from "react";
10
+ import type { ViewContext } from "copilotz";
11
+ import type { Board, Card } from "../../contract.js";
12
+ import { type Names, type Someone, type Team } from "./shown.js";
13
+ /** A space as `space.reached` answers: with what the person may do there. */
14
+ export type Place = {
15
+ _id: string;
16
+ name: string;
17
+ kind: string;
18
+ owner?: string;
19
+ archived?: string;
20
+ can?: string[];
21
+ };
22
+ /** What a space is called where it shows: yours is "Personal". */
23
+ export declare const placeName: (p?: Pick<Place, "name" | "kind">) => string;
24
+ export declare const placesOf: (ctx: ViewContext<ReactNode>) => Place[] | undefined;
25
+ export type Loaded = {
26
+ cards?: Card[];
27
+ people?: Someone[];
28
+ team?: Team;
29
+ names?: Names;
30
+ };
31
+ /** A board's cards, and who's in its space (people, then agents, shown as chat shows them). */
32
+ export declare function boardData(ctx: ViewContext<ReactNode>, board?: Board | null): Loaded;
@@ -0,0 +1,33 @@
1
+ import { namesIn } from "copilotz/plugins/access/contract";
2
+ import { peopleOf } from "./shown.js";
3
+ /** What a space is called where it shows: yours is "Personal". */
4
+ export const placeName = (p) => !p ? "this space" : p.kind === "personal" ? "Personal" : p.name;
5
+ export const placesOf = (ctx) => ctx.db.collection("space").query("reached", {}).value;
6
+ /** A board's cards, and who's in its space (people, then agents, shown as chat shows them). */
7
+ export function boardData(ctx, board) {
8
+ if (!board)
9
+ return {};
10
+ const cards = ctx.db.collection("card").find({ in: board.in, board: board._id }).value;
11
+ const members = ctx.db.collection("member").find({ space: board.in }).value;
12
+ const held = (cards ?? []).flatMap((c) => c.assignee ? [c.assignee] : []);
13
+ const agents = members
14
+ ? [...new Set([...members.map((m) => m.member), ...held])]
15
+ .filter((k) => k.startsWith("agent:")).map((k) => k.slice(6)).sort()
16
+ : undefined;
17
+ const team = agents
18
+ ? ctx.db.collection("thread").query("agents", { in: board.in, names: agents }).value
19
+ : undefined;
20
+ const names = namesIn(ctx, [
21
+ ...(members ?? []).map((m) => m.member),
22
+ ...held,
23
+ ...(cards ?? []).flatMap((c) => [c.by, c.updatedBy]),
24
+ ].filter((k) => !!k?.startsWith("person:")));
25
+ return {
26
+ cards,
27
+ ...(members && (team || !agents?.length)
28
+ ? { people: peopleOf(members, team, ctx.viewer?.name, held, names) }
29
+ : {}),
30
+ ...(team ? { team } : {}),
31
+ names,
32
+ };
33
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What boards offer in the command palette (kind `boards.palette`, the web
3
+ * shell's `palette` resource), for where the person is and what's typed:
4
+ *
5
+ * - **This board**, on a board's page: a new card on it (its title typed,
6
+ * then the column it goes in), its space's boards, deleting it;
7
+ * - **This space:** its Board tab;
8
+ * - **Boards**, while searching: every board the person reaches, to go to;
9
+ * - **Create:** a new board where they are, if they may write there (its
10
+ * name typed).
11
+ */
12
+ import type { ReactNode } from "react";
13
+ import type { ViewContext } from "copilotz";
14
+ import { type PaletteGroup } from "copilotz/web";
15
+ export declare const boardsPaletteView: (_: unknown, ctx: ViewContext<ReactNode>) => PaletteGroup[] | null;
@@ -0,0 +1,180 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { go } from "copilotz/web";
3
+ import { boardPath, boardsTab } from "../../contract.js";
4
+ import { Glyph } from "./glyphs.js";
5
+ import { placeName, placesOf } from "./load.js";
6
+ const mark = _jsx(Glyph, { name: "board", size: 18 });
7
+ /** A new card on a board: its title typed, then the column it goes in. */
8
+ const newCardStep = (board, call) => ({
9
+ title: `New card on ${board.name}`,
10
+ placeholder: "What's the outcome?",
11
+ filter: false,
12
+ items: (typed) => {
13
+ const title = typed.trim();
14
+ if (!title) {
15
+ return [{
16
+ title: "",
17
+ items: [{
18
+ key: "board:new-card:hint",
19
+ label: "Type the card's title, then choose its column",
20
+ icon: "compose",
21
+ disabled: true,
22
+ }],
23
+ }];
24
+ }
25
+ return [{
26
+ title: "Add it to",
27
+ items: board.columns.map((c) => ({
28
+ key: `board:new-card:${c.id}`,
29
+ label: `“${title.length > 48 ? `${title.slice(0, 47)}…` : title}” in ${c.name}`,
30
+ icon: "plus",
31
+ run: () => call("card.create", { board: board._id, title: title.slice(0, 300), column: c.id }),
32
+ })),
33
+ }];
34
+ },
35
+ });
36
+ /** A new board in a space: its name typed. */
37
+ const newBoardStep = (space, where, call) => ({
38
+ title: `New board in ${where}`,
39
+ placeholder: "Its name",
40
+ filter: false,
41
+ items: (typed) => {
42
+ const name = typed.trim();
43
+ return [{
44
+ title: "",
45
+ items: [
46
+ name
47
+ ? {
48
+ key: "board:create",
49
+ label: `Make the board “${name.slice(0, 80)}”`,
50
+ leading: mark,
51
+ run: async () => {
52
+ const { board } = await call("board.create", {
53
+ in: space,
54
+ name: name.slice(0, 80),
55
+ });
56
+ go(boardPath(board, space));
57
+ },
58
+ }
59
+ : {
60
+ key: "board:create:hint",
61
+ label: "Type the board's name",
62
+ icon: "compose",
63
+ disabled: true,
64
+ },
65
+ ],
66
+ }];
67
+ },
68
+ });
69
+ /** Deleting a board, once they've read that its cards go too. */
70
+ const deleteStep = (board, call) => ({
71
+ title: `Delete ${board.name}?`,
72
+ confirm: true,
73
+ note: "Its cards go with it, for everyone in the space. It can't be brought back.",
74
+ items: () => [{
75
+ title: "",
76
+ items: [
77
+ {
78
+ key: "board:delete",
79
+ label: `Delete ${board.name}`,
80
+ icon: "trash",
81
+ tone: "destructive",
82
+ run: async () => {
83
+ await call("board.delete", { board: board._id });
84
+ go(boardsTab(board.in));
85
+ },
86
+ },
87
+ { key: "board:keep", label: "Keep it", icon: "close", run: (p) => p.back() },
88
+ ],
89
+ }],
90
+ });
91
+ export const boardsPaletteView = (_, ctx) => {
92
+ const searching = !!String(ctx.hints.search ?? "").trim();
93
+ const here = typeof ctx.hints.in === "string" ? ctx.hints.in : undefined;
94
+ const page = (ctx.hints.page ?? {});
95
+ const places = placesOf(ctx);
96
+ const open = page.kind === "board" && page.id
97
+ ? ctx.db.collection("board").findOne({ _id: page.id }).value
98
+ : null;
99
+ // Every board the person reaches, only while searching.
100
+ const all = searching ? ctx.db.collection("board").find({}).value : [];
101
+ if (!places || open === undefined || !all)
102
+ return null;
103
+ const groups = [];
104
+ const space = open?.in ?? here;
105
+ const place = places.find((p) => p._id === space);
106
+ const can = !!place?.can?.includes("write") && !place.archived;
107
+ if (open) {
108
+ const items = [];
109
+ if (can) {
110
+ items.push({
111
+ key: "board:new-card",
112
+ label: "New card on this board…",
113
+ icon: "plus",
114
+ keywords: ["card", "task", "add", open.name],
115
+ step: newCardStep(open, ctx.call),
116
+ });
117
+ }
118
+ items.push({
119
+ key: "board:space",
120
+ label: `${placeName(place)}'s boards`,
121
+ leading: mark,
122
+ href: boardsTab(open.in),
123
+ });
124
+ if (can) {
125
+ items.push({
126
+ key: "board:delete-step",
127
+ label: `Delete ${open.name}…`,
128
+ icon: "trash",
129
+ tone: "destructive",
130
+ step: deleteStep(open, ctx.call),
131
+ });
132
+ }
133
+ // What's open comes first: before the space it's in.
134
+ groups.push({ title: "This board", order: 8, items });
135
+ }
136
+ else if (here && place) {
137
+ groups.push({
138
+ title: "This space",
139
+ order: 10,
140
+ items: [{
141
+ key: "board:tab",
142
+ label: "Board",
143
+ leading: mark,
144
+ description: "Where the work stands",
145
+ keywords: ["board", "boards", "kanban", "cards", "tasks"],
146
+ href: boardsTab(here),
147
+ }],
148
+ });
149
+ }
150
+ if (searching && all.length) {
151
+ groups.push({
152
+ title: "Boards",
153
+ order: 32,
154
+ limit: 6,
155
+ items: all.filter((b) => !b.archived).map((b) => ({
156
+ key: `board:${b._id}`,
157
+ label: b.name,
158
+ leading: mark,
159
+ description: placeName(places.find((p) => p._id === b.in)),
160
+ keywords: [b.description ?? "", "board"],
161
+ href: boardPath(b._id, b.in),
162
+ })),
163
+ });
164
+ }
165
+ if (space && place && can) {
166
+ groups.push({
167
+ title: "Create",
168
+ order: 40,
169
+ items: [{
170
+ key: "board:new",
171
+ label: "New board…",
172
+ leading: mark,
173
+ description: placeName(place),
174
+ keywords: ["board", "kanban", "project"],
175
+ step: newBoardStep(space, placeName(place), ctx.call),
176
+ }],
177
+ });
178
+ }
179
+ return groups;
180
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Choosing on a board, in popovers: whom a card goes to (the space's people
3
+ * and agents, found as you type), its labels (the board's, or a new one),
4
+ * and what the board is filtered by (owners, labels: several at once). Each
5
+ * list is a popover's items: arrows move, Enter chooses, Escape closes.
6
+ */
7
+ import { type ReactNode } from "react";
8
+ import { type PopoverTrigger } from "copilotz/web";
9
+ import { type Someone } from "./shown.js";
10
+ /** An option's face: a person's initial, an agent's emoji, or nobody's dashed ring. */
11
+ export declare function Face({ someone, size }: {
12
+ someone?: Someone;
13
+ size?: number;
14
+ }): ReactNode;
15
+ /** Whom a card goes to: one of the space's people or agents, or nobody. */
16
+ export declare function AssigneePicker({ people, value, onChange, trigger, label }: {
17
+ people: Someone[];
18
+ value?: string;
19
+ onChange(key: string | null): void;
20
+ trigger(props: PopoverTrigger): ReactNode;
21
+ label?: string;
22
+ }): ReactNode;
23
+ /** A card's labels: the board's to choose from, or a new one typed. */
24
+ export declare function LabelPicker({ known, value, onChange, trigger }: {
25
+ /** The board's labels, most used first. */
26
+ known: string[];
27
+ value: string[];
28
+ onChange(labels: string[]): void;
29
+ trigger(props: PopoverTrigger): ReactNode;
30
+ }): ReactNode;
31
+ /** Several of a list at once (a filter's owners or labels), each with how many cards have it. */
32
+ export declare function ManyPicker<T extends string>({ label, options, value, onChange, trigger, search }: {
33
+ label: string;
34
+ options: {
35
+ value: T;
36
+ label: string;
37
+ leading?: ReactNode;
38
+ count?: number;
39
+ }[];
40
+ value: T[];
41
+ onChange(value: T[]): void;
42
+ trigger(props: PopoverTrigger): ReactNode;
43
+ /** A field to narrow a long list. */
44
+ search?: string;
45
+ }): ReactNode;