@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,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown, written: what the editor's toolbar and shortcuts do to the text
|
|
3
|
+
* and its selection. Each takes the field as it is (its text, where the
|
|
4
|
+
* selection starts and ends) and says what to replace (`from` to `to` with
|
|
5
|
+
* `insert`) and what to select after, so the editor applies it as typing
|
|
6
|
+
* would, and undo undoes it. Pure, so tested.
|
|
7
|
+
*
|
|
8
|
+
* - **Marks** around the selection (bold, italic, code, strikethrough),
|
|
9
|
+
* or around the word at the caret, or, with nothing there, an empty pair
|
|
10
|
+
* to type in; marked already, they come off.
|
|
11
|
+
* - **Line kinds** on every line the selection touches (headings, lists,
|
|
12
|
+
* tasks, quotes); all of them that kind already, it comes off.
|
|
13
|
+
* - **Links:** the selection as a link's text, with its address selected.
|
|
14
|
+
* - **Enter** in a list goes on with it (the next number, an open task);
|
|
15
|
+
* on an empty item, the list ends. **Tab** in a list indents it, and
|
|
16
|
+
* Shift+Tab outdents.
|
|
17
|
+
*/
|
|
18
|
+
const MARKS = { bold: "**", italic: "_", code: "`", strike: "~~" };
|
|
19
|
+
/** What a field becomes with a change made. */
|
|
20
|
+
export const applied = (field, c) => ({
|
|
21
|
+
value: field.value.slice(0, c.from) + c.insert + field.value.slice(c.to),
|
|
22
|
+
start: c.select[0],
|
|
23
|
+
end: c.select[1],
|
|
24
|
+
});
|
|
25
|
+
const word = /[\p{L}\p{N}_'’-]/u;
|
|
26
|
+
/** Marks the selection (or the word at the caret), or takes the mark off what has it. */
|
|
27
|
+
export function mark(field, kind) {
|
|
28
|
+
const m = MARKS[kind];
|
|
29
|
+
let { start, end } = field;
|
|
30
|
+
const { value } = field;
|
|
31
|
+
if (start === end) {
|
|
32
|
+
// The word the caret is in.
|
|
33
|
+
while (start > 0 && word.test(value[start - 1]))
|
|
34
|
+
start--;
|
|
35
|
+
while (end < value.length && word.test(value[end]))
|
|
36
|
+
end++;
|
|
37
|
+
}
|
|
38
|
+
// Leading and trailing spaces stay outside the marks.
|
|
39
|
+
while (start < end && /\s/.test(value[start]))
|
|
40
|
+
start++;
|
|
41
|
+
while (end > start && /\s/.test(value[end - 1]))
|
|
42
|
+
end--;
|
|
43
|
+
const inner = value.slice(start, end);
|
|
44
|
+
const around = value.slice(start - m.length, start) === m &&
|
|
45
|
+
value.slice(end, end + m.length) === m;
|
|
46
|
+
if (around && inner) {
|
|
47
|
+
return {
|
|
48
|
+
from: start - m.length,
|
|
49
|
+
to: end + m.length,
|
|
50
|
+
insert: inner,
|
|
51
|
+
select: [start - m.length, end - m.length],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (inner.length >= 2 * m.length && inner.startsWith(m) && inner.endsWith(m)) {
|
|
55
|
+
const bare = inner.slice(m.length, -m.length);
|
|
56
|
+
return { from: start, to: end, insert: bare, select: [start, start + bare.length] };
|
|
57
|
+
}
|
|
58
|
+
if (!inner) {
|
|
59
|
+
const at = field.start;
|
|
60
|
+
return { from: at, to: field.end, insert: m + m, select: [at + m.length, at + m.length] };
|
|
61
|
+
}
|
|
62
|
+
// A selection across lines: code becomes a block.
|
|
63
|
+
if (kind === "code" && inner.includes("\n"))
|
|
64
|
+
return fence(field);
|
|
65
|
+
return {
|
|
66
|
+
from: start,
|
|
67
|
+
to: end,
|
|
68
|
+
insert: m + inner + m,
|
|
69
|
+
select: [start + m.length, end + m.length],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** The selection as a fenced code block, on lines of its own. */
|
|
73
|
+
export function fence(field) {
|
|
74
|
+
const { value } = field;
|
|
75
|
+
const [from, to] = lineSpan(value, field.start, field.end);
|
|
76
|
+
const inner = value.slice(from, to);
|
|
77
|
+
const insert = "```\n" + inner + "\n```";
|
|
78
|
+
return { from, to, insert, select: [from + 4, from + 4 + inner.length] };
|
|
79
|
+
}
|
|
80
|
+
const PREFIX = /^(\s*)(#{1,6}\s+|>\s?|[-*+]\s+\[[ xX]\]\s+|[-*+]\s+|\d+[.)]\s+)?/;
|
|
81
|
+
/** What a line is, from how it starts. */
|
|
82
|
+
export function kindOf(line) {
|
|
83
|
+
const p = line.match(PREFIX)?.[2] ?? "";
|
|
84
|
+
if (/^#\s/.test(p))
|
|
85
|
+
return "h1";
|
|
86
|
+
if (/^##\s/.test(p))
|
|
87
|
+
return "h2";
|
|
88
|
+
if (/^#{3,6}\s/.test(p))
|
|
89
|
+
return "h3";
|
|
90
|
+
if (/^>/.test(p))
|
|
91
|
+
return "quote";
|
|
92
|
+
if (/^[-*+]\s+\[/.test(p))
|
|
93
|
+
return "task";
|
|
94
|
+
if (/^[-*+]/.test(p))
|
|
95
|
+
return "bullet";
|
|
96
|
+
if (/^\d/.test(p))
|
|
97
|
+
return "number";
|
|
98
|
+
return "plain";
|
|
99
|
+
}
|
|
100
|
+
/** Where the lines the selection touches start and end. */
|
|
101
|
+
function lineSpan(value, start, end) {
|
|
102
|
+
const from = value.lastIndexOf("\n", start - 1) + 1;
|
|
103
|
+
// A selection that ends at a line's start doesn't take that line.
|
|
104
|
+
const last = end > start && value[end - 1] === "\n" ? end - 1 : end;
|
|
105
|
+
const next = value.indexOf("\n", last);
|
|
106
|
+
return [from, next < 0 ? value.length : next];
|
|
107
|
+
}
|
|
108
|
+
/** Makes every line the selection touches `kind` (numbered in order), or plain if all are. */
|
|
109
|
+
export function lines(field, kind) {
|
|
110
|
+
const { value } = field;
|
|
111
|
+
const [from, to] = lineSpan(value, field.start, field.end);
|
|
112
|
+
const old = value.slice(from, to).split("\n");
|
|
113
|
+
const said = old.filter((l) => l.trim());
|
|
114
|
+
const off = kind !== "plain" && said.length > 0 && said.every((l) => kindOf(l) === kind);
|
|
115
|
+
let n = 0;
|
|
116
|
+
const made = old.map((line) => {
|
|
117
|
+
const [, indent = "", prefix = ""] = line.match(PREFIX) ?? [];
|
|
118
|
+
const rest = line.slice(indent.length + prefix.length);
|
|
119
|
+
if (!line.trim() && old.length > 1)
|
|
120
|
+
return line;
|
|
121
|
+
if (off || kind === "plain")
|
|
122
|
+
return indent + rest;
|
|
123
|
+
n++;
|
|
124
|
+
const marker = kind === "h1"
|
|
125
|
+
? "# "
|
|
126
|
+
: kind === "h2"
|
|
127
|
+
? "## "
|
|
128
|
+
: kind === "h3"
|
|
129
|
+
? "### "
|
|
130
|
+
: kind === "quote"
|
|
131
|
+
? "> "
|
|
132
|
+
: kind === "task"
|
|
133
|
+
? "- [ ] "
|
|
134
|
+
: kind === "bullet"
|
|
135
|
+
? "- "
|
|
136
|
+
: `${n}. `;
|
|
137
|
+
return indent + marker + rest;
|
|
138
|
+
});
|
|
139
|
+
const insert = made.join("\n");
|
|
140
|
+
// A caret stays before the same words; a selection takes the lines whole.
|
|
141
|
+
if (field.start === field.end && old.length === 1) {
|
|
142
|
+
const at = Math.max(from, from + insert.length - (to - field.start));
|
|
143
|
+
return { from, to, insert, select: [at, at] };
|
|
144
|
+
}
|
|
145
|
+
return { from, to, insert, select: [from, from + insert.length] };
|
|
146
|
+
}
|
|
147
|
+
/** A heading that goes up a level each time: none, #, ##, ###, then none again. */
|
|
148
|
+
export function heading(field) {
|
|
149
|
+
const [from, to] = lineSpan(field.value, field.start, field.start);
|
|
150
|
+
const kind = kindOf(field.value.slice(from, to));
|
|
151
|
+
const next = kind === "h1"
|
|
152
|
+
? "h2"
|
|
153
|
+
: kind === "h2"
|
|
154
|
+
? "h3"
|
|
155
|
+
: kind === "h3"
|
|
156
|
+
? "plain"
|
|
157
|
+
: "h1";
|
|
158
|
+
return lines(field, next);
|
|
159
|
+
}
|
|
160
|
+
/** The selection as a link's text (or a link to type), its address selected to type over. */
|
|
161
|
+
export function link(field, href = "https://") {
|
|
162
|
+
const { value, start, end } = field;
|
|
163
|
+
const text = value.slice(start, end);
|
|
164
|
+
if (/^(https?:\/\/|mailto:|\/)\S*$/.test(text)) {
|
|
165
|
+
const insert = `[](${text})`;
|
|
166
|
+
return { from: start, to: end, insert, select: [start + 1, start + 1] };
|
|
167
|
+
}
|
|
168
|
+
const shown = text || "link";
|
|
169
|
+
const insert = `[${shown}](${href})`;
|
|
170
|
+
const at = start + shown.length + 3;
|
|
171
|
+
return {
|
|
172
|
+
from: start,
|
|
173
|
+
to: end,
|
|
174
|
+
insert,
|
|
175
|
+
select: text ? [at, at + href.length] : [start + 1, start + 1 + shown.length],
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Pasting an address over selected words: they become its link. */
|
|
179
|
+
export function pasted(field, clip) {
|
|
180
|
+
const url = clip.trim();
|
|
181
|
+
const text = field.value.slice(field.start, field.end);
|
|
182
|
+
if (!text || text.includes("\n") || !/^(https?:\/\/|mailto:)\S+$/.test(url))
|
|
183
|
+
return undefined;
|
|
184
|
+
const insert = `[${text}](${url})`;
|
|
185
|
+
return {
|
|
186
|
+
from: field.start,
|
|
187
|
+
to: field.end,
|
|
188
|
+
insert,
|
|
189
|
+
select: [field.start + insert.length, field.start + insert.length],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** Enter in a list item: the next item, or the end of the list on an empty one. */
|
|
193
|
+
export function enter(field) {
|
|
194
|
+
const { value, start, end } = field;
|
|
195
|
+
if (start !== end)
|
|
196
|
+
return undefined;
|
|
197
|
+
const from = value.lastIndexOf("\n", start - 1) + 1;
|
|
198
|
+
const line = value.slice(from, start);
|
|
199
|
+
const m = line.match(/^(\s*)(>\s?|[-*+]\s+\[[ xX]\]\s+|[-*+]\s+|(\d+)([.)])\s+)/);
|
|
200
|
+
if (!m)
|
|
201
|
+
return undefined;
|
|
202
|
+
const [prefix, indent, , number, dot] = m;
|
|
203
|
+
const eol = value.indexOf("\n", start);
|
|
204
|
+
const rest = value.slice(start, eol < 0 ? value.length : eol);
|
|
205
|
+
if (line.length === prefix.length && !rest.trim()) {
|
|
206
|
+
// An empty item ends the list: its marks go.
|
|
207
|
+
return {
|
|
208
|
+
from,
|
|
209
|
+
to: start,
|
|
210
|
+
insert: indent,
|
|
211
|
+
select: [from + indent.length, from + indent.length],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const next = number !== undefined
|
|
215
|
+
? `${indent}${Number(number) + 1}${dot} `
|
|
216
|
+
: /\[[ xX]\]/.test(prefix)
|
|
217
|
+
? `${indent}${prefix.trim()[0]} [ ] `
|
|
218
|
+
: prefix;
|
|
219
|
+
const insert = `\n${next}`;
|
|
220
|
+
return { from: start, to: end, insert, select: [start + insert.length, start + insert.length] };
|
|
221
|
+
}
|
|
222
|
+
/** Tab in a list: its lines in by two spaces, or (`out`) back out. Elsewhere, nothing. */
|
|
223
|
+
export function indent(field, out = false) {
|
|
224
|
+
const { value } = field;
|
|
225
|
+
const [from, to] = lineSpan(value, field.start, field.end);
|
|
226
|
+
const old = value.slice(from, to).split("\n");
|
|
227
|
+
if (!old.every((l) => !l.trim() || /^\s*([-*+]\s|\d+[.)]\s)/.test(l)))
|
|
228
|
+
return undefined;
|
|
229
|
+
const made = old.map((l) => out ? l.replace(/^ {1,2}/, "") : l.trim() ? ` ${l}` : l);
|
|
230
|
+
const insert = made.join("\n");
|
|
231
|
+
if (insert === old.join("\n"))
|
|
232
|
+
return undefined;
|
|
233
|
+
const firstShift = made[0].length - old[0].length;
|
|
234
|
+
const caret = field.start === field.end && old.length === 1;
|
|
235
|
+
return {
|
|
236
|
+
from,
|
|
237
|
+
to,
|
|
238
|
+
insert,
|
|
239
|
+
select: caret
|
|
240
|
+
? [Math.max(from, field.start + firstShift), Math.max(from, field.start + firstShift)]
|
|
241
|
+
: [from, from + insert.length],
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** How many words a text has. */
|
|
245
|
+
export const wordsIn = (text) => text.match(/[\p{L}\p{N}][\p{L}\p{N}'’_-]*/gu)?.length ?? 0;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A document's History (kind `document.history`, item `{ _id }`, shown in
|
|
3
|
+
* its page's drawer; hints `{ write }`, whether the person may restore):
|
|
4
|
+
* every version, newest first, with who saved it (an agent, for whom), when,
|
|
5
|
+
* how (made, saved, merged, renamed, restored, an agent's write, append or
|
|
6
|
+
* edit) and the lines it added and removed. One opens (kind
|
|
7
|
+
* `document.version`) as the change from the one before, in the toolkit's
|
|
8
|
+
* added and removed tones, or as it read then; those who may change the
|
|
9
|
+
* document restore it, as a new version.
|
|
10
|
+
*/
|
|
11
|
+
import { type ReactNode } from "react";
|
|
12
|
+
import type { ViewContext } from "copilotz";
|
|
13
|
+
import type { Saved } from "../../contract.js";
|
|
14
|
+
/** How a version came to be, in a few words. */
|
|
15
|
+
export declare function how(v: Saved): string;
|
|
16
|
+
/** The page tells its drawer a version was restored with this event, to close it and say so. */
|
|
17
|
+
export declare const RESTORED = "documents:restored";
|
|
18
|
+
export declare const historyView: (item: {
|
|
19
|
+
_id?: string;
|
|
20
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
21
|
+
export declare const versionView: (item: {
|
|
22
|
+
_id?: string;
|
|
23
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A document's History (kind `document.history`, item `{ _id }`, shown in
|
|
4
|
+
* its page's drawer; hints `{ write }`, whether the person may restore):
|
|
5
|
+
* every version, newest first, with who saved it (an agent, for whom), when,
|
|
6
|
+
* how (made, saved, merged, renamed, restored, an agent's write, append or
|
|
7
|
+
* edit) and the lines it added and removed. One opens (kind
|
|
8
|
+
* `document.version`) as the change from the one before, in the toolkit's
|
|
9
|
+
* added and removed tones, or as it read then; those who may change the
|
|
10
|
+
* document restore it, as a new version.
|
|
11
|
+
*/
|
|
12
|
+
import { useState } from "react";
|
|
13
|
+
import { Badge, Button, CopyButton, Icon, LazyView, Markdown, message, Notice, Skeleton, Tabs, Time, } from "copilotz/web";
|
|
14
|
+
import { versionId } from "../../shared/text.js";
|
|
15
|
+
import { Counts, Diff } from "./changes.js";
|
|
16
|
+
import { Face, said, shownAs, whoIn } from "./people.js";
|
|
17
|
+
/** How a version came to be, in a few words. */
|
|
18
|
+
export function how(v) {
|
|
19
|
+
switch (v.kind) {
|
|
20
|
+
case "create":
|
|
21
|
+
return "Made it";
|
|
22
|
+
case "rename":
|
|
23
|
+
return v.renamed ? `Renamed from “${v.renamed}”` : "Renamed it";
|
|
24
|
+
case "restore":
|
|
25
|
+
return `Brought back version ${v.from}`;
|
|
26
|
+
case "write":
|
|
27
|
+
return "Rewrote it";
|
|
28
|
+
case "append":
|
|
29
|
+
return "Added to the end";
|
|
30
|
+
case "edit":
|
|
31
|
+
return "Edited part of it";
|
|
32
|
+
default:
|
|
33
|
+
return v.merged ? `Saved, merged over changes since version ${v.base}` : "Saved";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The page tells its drawer a version was restored with this event, to close it and say so. */
|
|
37
|
+
export const RESTORED = "documents:restored";
|
|
38
|
+
export const historyView = (item, ctx) => {
|
|
39
|
+
const id = item._id ?? "";
|
|
40
|
+
const versions = ctx.db.collection("documentVersion").query("history", {
|
|
41
|
+
document: id,
|
|
42
|
+
}).value;
|
|
43
|
+
const known = whoIn(ctx, (versions ?? []).flatMap((v) => [v.by, v.for]));
|
|
44
|
+
if (!versions) {
|
|
45
|
+
return (_jsx("div", { className: "doc-history-list", "aria-busy": "true", children: [0, 1, 2, 3].map((i) => _jsx(Skeleton, { height: 58, radius: "lg" }, i)) }));
|
|
46
|
+
}
|
|
47
|
+
const start = typeof ctx.hints.version === "number" ? ctx.hints.version : undefined;
|
|
48
|
+
return (_jsx(History, { document: id, versions: versions, shown: (key) => shownAs(key, known), me: ctx.viewer?.name, write: ctx.hints.write === true, start: start }));
|
|
49
|
+
};
|
|
50
|
+
function History({ document, versions, shown, me, write, start }) {
|
|
51
|
+
const [open, setOpen] = useState(start);
|
|
52
|
+
const latest = versions[0]?.version ?? 0;
|
|
53
|
+
if (open !== undefined) {
|
|
54
|
+
return (_jsxs("div", { className: "doc-history-one", children: [_jsx(Button, { variant: "ghost", size: "sm", icon: "chevron-left", onClick: () => setOpen(undefined), children: "All versions" }), _jsx(LazyView, { kind: "document.version", item: { _id: versionId(document, open) }, hints: { write, latest } })] }));
|
|
55
|
+
}
|
|
56
|
+
return (_jsx("ol", { className: "doc-history-list", "aria-label": "Versions, newest first", children: versions.map((v) => {
|
|
57
|
+
const who = shown(v.by);
|
|
58
|
+
const helped = v.for ? shown(v.for) : undefined;
|
|
59
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "doc-version-row", "aria-current": v.version === latest ? "true" : undefined, onClick: () => setOpen(v.version), children: [_jsx(Face, { who: who, size: 28 }), _jsxs("span", { className: "doc-version-text", children: [_jsxs("span", { className: "doc-version-top", children: [_jsxs("b", { children: ["Version ", v.version] }), v.version === latest ? _jsx(Badge, { tone: "primary", children: "Now" }) : null, v.merged ? _jsx(Badge, { tone: "info", children: "Merged" }) : null] }), _jsxs("span", { className: "doc-version-what", children: [said(who, me), helped ? ` for ${said(helped, me, false)}` : "", " \u00B7 ", how(v)] })] }), _jsxs("span", { className: "doc-version-end", children: [_jsx(Counts, { added: v.added, removed: v.removed }), _jsx(Time, { at: v.at })] })] }) }, v._id));
|
|
60
|
+
}) }));
|
|
61
|
+
}
|
|
62
|
+
export const versionView = (item, ctx) => {
|
|
63
|
+
const id = item._id ?? "";
|
|
64
|
+
const v = ctx.db.collection("documentVersion").findOne({ _id: id }).value;
|
|
65
|
+
const before = v && v.version > 1
|
|
66
|
+
? ctx.db.collection("documentVersion").findOne({
|
|
67
|
+
_id: versionId(v.document, v.version - 1),
|
|
68
|
+
}).value
|
|
69
|
+
: null;
|
|
70
|
+
const known = whoIn(ctx, [v?.by, v?.for]);
|
|
71
|
+
if (v === undefined || before === undefined) {
|
|
72
|
+
return (_jsxs("div", { className: "doc-version", "aria-busy": "true", children: [_jsx(Skeleton, { height: 22, width: "60%" }), _jsx(Skeleton, { height: 260, radius: "lg" })] }));
|
|
73
|
+
}
|
|
74
|
+
if (!v)
|
|
75
|
+
return _jsx(Notice, { tone: "neutral", children: "This version isn't here any more." });
|
|
76
|
+
return (_jsx(Version, { v: v, before: before, shown: (key) => shownAs(key, known), me: ctx.viewer?.name, write: ctx.hints.write === true, latest: Number(ctx.hints.latest) || v.version, call: ctx.call }));
|
|
77
|
+
};
|
|
78
|
+
function Version({ v, before, shown, me, write, latest, call }) {
|
|
79
|
+
const [tab, setTab] = useState(v.version === 1 ? "read" : "changes");
|
|
80
|
+
const [asking, setAsking] = useState(false);
|
|
81
|
+
const [busy, setBusy] = useState(false);
|
|
82
|
+
const [error, setError] = useState();
|
|
83
|
+
const who = shown(v.by);
|
|
84
|
+
const helped = v.for ? shown(v.for) : undefined;
|
|
85
|
+
const restore = async () => {
|
|
86
|
+
setBusy(true);
|
|
87
|
+
setError(undefined);
|
|
88
|
+
try {
|
|
89
|
+
const done = await call("document.restore", {
|
|
90
|
+
document: v.document,
|
|
91
|
+
version: v.version,
|
|
92
|
+
});
|
|
93
|
+
globalThis.dispatchEvent(new CustomEvent(RESTORED, {
|
|
94
|
+
detail: { document: v.document, from: v.version, version: done.version },
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
setError(message(e));
|
|
99
|
+
setBusy(false);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return (_jsxs("article", { className: "doc-version", "aria-label": `Version ${v.version}`, children: [_jsxs("header", { className: "doc-version-head", children: [_jsx(Face, { who: who, size: 34 }), _jsxs("div", { children: [_jsxs("h3", { children: ["Version ", v.version, v.version === latest ? _jsx(Badge, { tone: "primary", children: "Now" }) : null] }), _jsxs("p", { children: [said(who, me), helped ? ` for ${said(helped, me, false)}` : "", " \u00B7 ", _jsx(Time, { at: v.at, long: true }), " \u00B7 ", how(v)] })] }), _jsx(Counts, { added: v.added, removed: v.removed })] }), v.renamed && v.renamed !== v.title
|
|
103
|
+
? (_jsxs("p", { className: "doc-version-renamed", children: [_jsx(Icon, { name: "pencil", size: 13 }), " Title: \u201C", v.renamed, "\u201D \u2192 ", _jsxs("b", { children: ["\u201C", v.title, "\u201D"] })] }))
|
|
104
|
+
: null, _jsx(Tabs, { label: "Show", variant: "line", value: tab, onChange: setTab, tabs: [
|
|
105
|
+
...(before
|
|
106
|
+
? [{ value: "changes", label: `Changes from version ${before.version}` }]
|
|
107
|
+
: []),
|
|
108
|
+
{ value: "read", label: "As it read" },
|
|
109
|
+
] }), tab === "changes" && before
|
|
110
|
+
? _jsx(Diff, { before: before.text, after: v.text })
|
|
111
|
+
: (_jsxs("div", { className: "doc-version-read", children: [_jsx("span", { className: "doc-version-copy", children: _jsx(CopyButton, { text: v.text, label: "Copy its Markdown" }) }), _jsx("h4", { className: "doc-version-title", children: v.title }), v.text.trim()
|
|
112
|
+
? _jsx(Markdown, { text: v.text, className: "doc-md doc-md-small" })
|
|
113
|
+
: _jsx("p", { className: "doc-empty-preview", children: "It was empty." })] })), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, write && v.version !== latest
|
|
114
|
+
? (_jsx("div", { className: "doc-version-foot", children: asking
|
|
115
|
+
? (_jsxs(Notice, { tone: "info", icon: "restore", title: `Bring back version ${v.version}?`, action: _jsxs("span", { className: "doc-version-ask", children: [_jsx(Button, { size: "sm", variant: "primary", loading: busy, onClick: () => void restore(), children: "Restore it" }), _jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => setAsking(false), children: "Cancel" })] }), children: ["It becomes version", " ", latest + 1, ", for everyone here. Nothing is lost: every version stays in History."] }))
|
|
116
|
+
: (_jsx(Button, { icon: "restore", onClick: () => setAsking(true), children: "Restore this version" })) }))
|
|
117
|
+
: null] }));
|
|
118
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A space's documents (kind `documents`: its Documents tab, item `{ _id }`,
|
|
3
|
+
* the space): each one's title, how it opens, who changed it last and when,
|
|
4
|
+
* how many versions it has, and who's in it right now; latest first, with a
|
|
5
|
+
* search once there are many. A new one in a click (or from a template),
|
|
6
|
+
* each one's menu (copy its link, rename, delete). With none yet, it says
|
|
7
|
+
* what documents are for here, and how to start one.
|
|
8
|
+
*
|
|
9
|
+
* Beside a chat (`hints.mode === "panel"`), the same, compact; a document
|
|
10
|
+
* opens there to read (kind `document.read`), with Edit opening its page.
|
|
11
|
+
*/
|
|
12
|
+
import { type ReactNode } from "react";
|
|
13
|
+
import type { ViewContext } from "copilotz";
|
|
14
|
+
import { type PaletteStep } from "copilotz/web";
|
|
15
|
+
import type { Listed } from "../../contract.js";
|
|
16
|
+
import { type Call } from "./people.js";
|
|
17
|
+
/** Ways to start, each a title and the bones of what goes under it. */
|
|
18
|
+
export declare const TEMPLATES: {
|
|
19
|
+
key: string;
|
|
20
|
+
label: string;
|
|
21
|
+
title: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}[];
|
|
24
|
+
/** Makes a document in `space` and opens it, its title ready to type over. */
|
|
25
|
+
export declare function newDocument(call: Call, space: string, start?: {
|
|
26
|
+
title?: string;
|
|
27
|
+
text?: string;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
/** Renaming a document from the command palette: its title, ready to type over. */
|
|
30
|
+
export declare function renameStep(doc: Pick<Listed, "_id" | "title">, call: Call): PaletteStep;
|
|
31
|
+
export declare const documentsView: (item: {
|
|
32
|
+
_id?: string;
|
|
33
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
34
|
+
/** A document to read beside a chat (kind `document.read`, item `{ _id }`): Edit opens its page. */
|
|
35
|
+
export declare const readView: (item: {
|
|
36
|
+
_id?: string;
|
|
37
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A space's documents (kind `documents`: its Documents tab, item `{ _id }`,
|
|
4
|
+
* the space): each one's title, how it opens, who changed it last and when,
|
|
5
|
+
* how many versions it has, and who's in it right now; latest first, with a
|
|
6
|
+
* search once there are many. A new one in a click (or from a template),
|
|
7
|
+
* each one's menu (copy its link, rename, delete). With none yet, it says
|
|
8
|
+
* what documents are for here, and how to start one.
|
|
9
|
+
*
|
|
10
|
+
* Beside a chat (`hints.mode === "panel"`), the same, compact; a document
|
|
11
|
+
* opens there to read (kind `document.read`), with Edit opening its page.
|
|
12
|
+
*/
|
|
13
|
+
import { useState } from "react";
|
|
14
|
+
import { Button, Chip, EmptyState, go, Icon, IconButton, Input, LazyView, Markdown, Menu, message, Notice, openPalette, Skeleton, Time, } from "copilotz/web";
|
|
15
|
+
import { documentPath, kb, TITLE } from "../../shared/text.js";
|
|
16
|
+
import { DeleteDialog } from "./page.js";
|
|
17
|
+
import { count, Face, placeName, said, shownAs, useNow, whoIn, writes, } from "./people.js";
|
|
18
|
+
import { hereNow, named, Present } from "./presence.js";
|
|
19
|
+
import { STYLE } from "./style.js";
|
|
20
|
+
const style = _jsx("style", { href: "documents-web", precedence: "copilotz", children: STYLE });
|
|
21
|
+
/** Past this many, a search shows. */
|
|
22
|
+
const SEARCHED = 6;
|
|
23
|
+
/** Ways to start, each a title and the bones of what goes under it. */
|
|
24
|
+
export const TEMPLATES = [
|
|
25
|
+
{
|
|
26
|
+
key: "plan",
|
|
27
|
+
label: "A plan",
|
|
28
|
+
title: "Plan",
|
|
29
|
+
text: "## Goal\n\nWhat we're after, and how we'll know we got there.\n\n## Steps\n\n- [ ] \n\n" +
|
|
30
|
+
"## Risks\n\n- \n\n## Open questions\n\n- ",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "meeting",
|
|
34
|
+
label: "Meeting notes",
|
|
35
|
+
title: "Meeting notes",
|
|
36
|
+
text: "**When:** \n**Who:** \n\n## Agenda\n\n- \n\n## Notes\n\n\n\n## Decisions\n\n- \n\n" +
|
|
37
|
+
"## Next steps\n\n- [ ] ",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "decision",
|
|
41
|
+
label: "A decision",
|
|
42
|
+
title: "Decision: ",
|
|
43
|
+
text: "## Context\n\nWhat's going on, and why we must choose.\n\n## Options\n\n1. \n2. \n\n" +
|
|
44
|
+
"## Decision\n\n\n\n## What follows from it\n\n- ",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: "brief",
|
|
48
|
+
label: "A brief",
|
|
49
|
+
title: "Brief",
|
|
50
|
+
text: "## The problem\n\n\n\n## Who it's for\n\n\n\n## What good looks like\n\n\n\n" +
|
|
51
|
+
"## Constraints\n\n- ",
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
/** Makes a document in `space` and opens it, its title ready to type over. */
|
|
55
|
+
export async function newDocument(call, space, start) {
|
|
56
|
+
const { document } = await call("document.create", {
|
|
57
|
+
in: space,
|
|
58
|
+
...(start?.title ? { title: start.title } : {}),
|
|
59
|
+
...(start?.text ? { text: start.text } : {}),
|
|
60
|
+
});
|
|
61
|
+
go(`${documentPath(document, space)}&new=1`);
|
|
62
|
+
}
|
|
63
|
+
/** Renaming a document from the command palette: its title, ready to type over. */
|
|
64
|
+
export function renameStep(doc, call) {
|
|
65
|
+
return {
|
|
66
|
+
title: `Rename “${doc.title}”`,
|
|
67
|
+
placeholder: "Its new title",
|
|
68
|
+
value: doc.title,
|
|
69
|
+
note: "A new title is a new version: everyone here sees it, and History keeps the old one.",
|
|
70
|
+
filter: false,
|
|
71
|
+
items: (search) => {
|
|
72
|
+
const title = search.trim();
|
|
73
|
+
if (!title || title === doc.title)
|
|
74
|
+
return [];
|
|
75
|
+
const long = title.length > TITLE;
|
|
76
|
+
return [{
|
|
77
|
+
title: "",
|
|
78
|
+
items: [{
|
|
79
|
+
key: "document:rename",
|
|
80
|
+
label: `Rename to “${title}”`,
|
|
81
|
+
icon: "pencil",
|
|
82
|
+
disabled: long,
|
|
83
|
+
...(long ? { description: `At most ${TITLE} characters` } : {}),
|
|
84
|
+
run: () => call("document.rename", { document: doc._id, title }),
|
|
85
|
+
}],
|
|
86
|
+
}];
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Text as it's matched: any case, any accents. */
|
|
91
|
+
const fold = (text) => text.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
92
|
+
export const documentsView = (item, ctx) => {
|
|
93
|
+
const space = item._id ?? (typeof ctx.hints.in === "string" ? ctx.hints.in : "");
|
|
94
|
+
const compact = ctx.hints.mode === "panel";
|
|
95
|
+
const listed = ctx.db.collection("document").query("list", { in: space }).value;
|
|
96
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
97
|
+
const presence = ctx.db.collection("documentPresence").find({ in: space }).value;
|
|
98
|
+
const known = whoIn(ctx, [
|
|
99
|
+
...(listed ?? []).flatMap((d) => [d.savedBy, d.savedFor]),
|
|
100
|
+
...(presence ?? []).map((p) => p.who),
|
|
101
|
+
]);
|
|
102
|
+
if (!listed || !places) {
|
|
103
|
+
return (_jsxs("div", { className: `docs${compact ? " docs-compact" : ""}`, "aria-busy": "true", children: [style, [0, 1, 2].map((i) => _jsx(Skeleton, { height: compact ? 54 : 84, radius: "lg" }, i))] }));
|
|
104
|
+
}
|
|
105
|
+
const place = places.find((p) => p._id === space);
|
|
106
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(Documents, { space: space, where: place ? placeName(place) : "this space", write: writes(place), docs: listed, presence: presence ?? [], shown: (key) => shownAs(key, known), me: ctx.viewer?.name, compact: compact, call: ctx.call })] }));
|
|
107
|
+
};
|
|
108
|
+
function Documents({ space, where, write, docs, presence, shown, me, compact, call }) {
|
|
109
|
+
const [search, setSearch] = useState("");
|
|
110
|
+
const [busy, setBusy] = useState();
|
|
111
|
+
const [error, setError] = useState();
|
|
112
|
+
const [reading, setReading] = useState();
|
|
113
|
+
const [deleting, setDeleting] = useState();
|
|
114
|
+
const now = useNow(15_000);
|
|
115
|
+
const start = async (key, from) => {
|
|
116
|
+
setBusy(key);
|
|
117
|
+
setError(undefined);
|
|
118
|
+
try {
|
|
119
|
+
await newDocument(call, space, from);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
setError(message(e));
|
|
123
|
+
setBusy(undefined);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
if (compact && reading) {
|
|
127
|
+
return (_jsxs("div", { className: "docs docs-compact", children: [_jsx("div", { className: "docs-reader-back", children: _jsx(Button, { variant: "ghost", size: "sm", icon: "chevron-left", onClick: () => setReading(undefined), children: "Documents" }) }), _jsx(LazyView, { kind: "document.read", item: { _id: reading }, hints: { in: space, mode: "panel" } })] }));
|
|
128
|
+
}
|
|
129
|
+
const failed = error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null;
|
|
130
|
+
if (!docs.length) {
|
|
131
|
+
return (_jsxs("div", { className: `docs${compact ? " docs-compact" : ""}`, children: [_jsx(EmptyState, { icon: "file", tone: "primary", title: "Write it down, together", className: "docs-empty", action: write
|
|
132
|
+
? (_jsx(Button, { variant: "primary", icon: "plus", loading: busy === "blank", onClick: () => void start("blank"), children: "New document" }))
|
|
133
|
+
: null, children: "Documents hold the work itself: the plan, the draft, the decision. Everyone here, people and agents, reads and improves the same one, and every save is a version you can compare or bring back." }), failed, write
|
|
134
|
+
? (_jsxs("div", { className: "docs-start", children: [_jsx("p", { className: "docs-start-label", children: "Or start from" }), _jsx("div", { className: "docs-start-chips", children: TEMPLATES.map((t) => (_jsx(Chip, { variant: "outline", onClick: () => void start(t.key, t), children: busy === t.key ? "Making it…" : t.label }, t.key))) }), _jsxs("p", { className: "docs-start-hint", children: [_jsx(Icon, { name: "sparkles", size: 14 }), " ", "Or ask an agent in a chat here: \u201Cdraft our launch plan as a document\u201D. It shows up here, and you'll see each change it makes."] })] }))
|
|
135
|
+
: (_jsxs("p", { className: "docs-start-hint", children: ["Editors of ", where, " add documents here, and so do its agents."] }))] }));
|
|
136
|
+
}
|
|
137
|
+
const words = fold(search).split(/\s+/).filter(Boolean);
|
|
138
|
+
const found = docs.filter((d) => {
|
|
139
|
+
const text = fold(`${d.title} ${d.excerpt}`);
|
|
140
|
+
return words.every((w) => text.includes(w));
|
|
141
|
+
});
|
|
142
|
+
const rows = found.map((d) => {
|
|
143
|
+
const who = shown(d.savedBy);
|
|
144
|
+
const here = hereNow(presence.filter((p) => p.document === d._id), now, me, shown);
|
|
145
|
+
const editing = here.filter((h) => h.editing);
|
|
146
|
+
const items = [
|
|
147
|
+
{ label: "Open", icon: "external", href: documentPath(d._id, space) },
|
|
148
|
+
{
|
|
149
|
+
label: "Copy link",
|
|
150
|
+
icon: "copy",
|
|
151
|
+
onSelect: () => void navigator.clipboard?.writeText(`${location.origin}/document/${d._id}`),
|
|
152
|
+
},
|
|
153
|
+
...(write
|
|
154
|
+
? [
|
|
155
|
+
{
|
|
156
|
+
label: "Rename…",
|
|
157
|
+
icon: "pencil",
|
|
158
|
+
onSelect: () => openPalette(renameStep(d, call)),
|
|
159
|
+
},
|
|
160
|
+
"separator",
|
|
161
|
+
{
|
|
162
|
+
label: "Delete…",
|
|
163
|
+
icon: "trash",
|
|
164
|
+
tone: "destructive",
|
|
165
|
+
onSelect: () => setDeleting(d),
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
: []),
|
|
169
|
+
];
|
|
170
|
+
const open = compact
|
|
171
|
+
? { as: "button", onClick: () => setReading(d._id) }
|
|
172
|
+
: { as: "a", href: documentPath(d._id, space) };
|
|
173
|
+
const inner = (_jsxs(_Fragment, { children: [_jsx("span", { className: "docs-row-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "file", size: compact ? 15 : 17 }) }), _jsxs("span", { className: "docs-row-text", children: [_jsx("span", { className: "docs-row-title", children: d.title }), d.excerpt && !compact ? _jsx("span", { className: "docs-row-excerpt", children: d.excerpt }) : null, _jsxs("span", { className: "docs-row-meta", children: [_jsx(Face, { who: who, size: 16 }), _jsx("span", { children: said(who, me) }), _jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsx(Time, { at: d.savedAt }), compact ? null : (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsx("span", { children: count(d.version, "version") }), _jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsx("span", { children: kb(d.size) })] }))] })] }), here.length
|
|
174
|
+
? (_jsxs("span", { className: "docs-row-here", children: [editing.length && !compact
|
|
175
|
+
? _jsxs("span", { className: "docs-row-editing", children: [named(editing), " editing"] })
|
|
176
|
+
: null, _jsx(Present, { here: here, most: 3, size: 20 })] }))
|
|
177
|
+
: null] }));
|
|
178
|
+
return (_jsxs("li", { className: "docs-item", children: [open.as === "a"
|
|
179
|
+
? _jsx("a", { className: "docs-row", href: open.href, children: inner })
|
|
180
|
+
: _jsx("button", { type: "button", className: "docs-row", onClick: open.onClick, children: inner }), _jsx("span", { className: "docs-row-menu", children: _jsx(Menu, { label: `${d.title}: more`, align: "end", size: "sm", items: items }) })] }, d._id));
|
|
181
|
+
});
|
|
182
|
+
return (_jsxs("div", { className: `docs${compact ? " docs-compact" : ""}`, children: [compact ? null : (_jsxs("div", { className: "docs-head", children: [_jsx("p", { className: "docs-intro", children: "The work itself, written down: people and agents here read and improve the same documents, and every save is a version." }), write
|
|
183
|
+
? (_jsx(Button, { variant: "primary", icon: "plus", loading: busy === "blank", onClick: () => void start("blank"), children: "New document" }))
|
|
184
|
+
: null] })), failed, docs.length > SEARCHED || compact
|
|
185
|
+
? (_jsxs("div", { className: "docs-head", children: [_jsx(Input, { icon: "search", type: "search", size: compact ? "sm" : "md", className: "docs-search", "aria-label": "Search documents", placeholder: `Search ${count(docs.length, "document")}`, autoComplete: "off", value: search, onChange: (event) => setSearch(event.target.value) }), compact && write
|
|
186
|
+
? (_jsx(IconButton, { icon: "plus", label: "New document", variant: "outline", loading: busy === "blank", onClick: () => void start("blank") }))
|
|
187
|
+
: null] }))
|
|
188
|
+
: null, rows.length
|
|
189
|
+
? _jsx("ul", { className: "docs-list", "aria-label": `Documents in ${where}`, children: rows })
|
|
190
|
+
: _jsxs("p", { className: "docs-none", children: ["No documents match \u201C", search, "\u201D."] }), deleting
|
|
191
|
+
? (_jsx(DeleteDialog, { open: true, onClose: () => setDeleting(undefined), doc: deleting, where: where, call: call }))
|
|
192
|
+
: null] }));
|
|
193
|
+
}
|
|
194
|
+
/** A document to read beside a chat (kind `document.read`, item `{ _id }`): Edit opens its page. */
|
|
195
|
+
export const readView = (item, ctx) => {
|
|
196
|
+
const id = item._id ?? "";
|
|
197
|
+
const doc = ctx.db.collection("document").findOne({ _id: id }).value;
|
|
198
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
199
|
+
const known = whoIn(ctx, [doc?.savedBy, doc?.savedFor]);
|
|
200
|
+
if (doc === undefined || !places) {
|
|
201
|
+
return (_jsxs("div", { className: "doc-reader", "aria-busy": "true", children: [style, _jsx(Skeleton, { height: 24, width: "70%" }), _jsx(Skeleton, { height: 200, radius: "lg" })] }));
|
|
202
|
+
}
|
|
203
|
+
if (!doc) {
|
|
204
|
+
return (_jsxs("div", { className: "doc-reader", children: [style, _jsx(Notice, { tone: "neutral", children: "This document isn't here any more." })] }));
|
|
205
|
+
}
|
|
206
|
+
const place = places.find((p) => p._id === doc.in);
|
|
207
|
+
const who = shownAs(doc.savedBy, known);
|
|
208
|
+
return (_jsxs("article", { className: "doc-reader", "aria-labelledby": `doc-reader-${id}`, children: [style, _jsxs("header", { className: "doc-reader-head", children: [_jsxs("div", { children: [_jsx("h2", { id: `doc-reader-${id}`, children: doc.title }), _jsxs("p", { children: ["Version ", doc.version, " \u00B7 ", said(who, ctx.viewer?.name), " \u00B7 ", _jsx(Time, { at: doc.savedAt })] })] }), _jsx(Button, { size: "sm", variant: writes(place) ? "primary" : "outline", icon: writes(place) ? "pencil" : "external", href: documentPath(doc._id, doc.in), children: writes(place) ? "Edit" : "Open" })] }), doc.text.trim()
|
|
209
|
+
? _jsx(Markdown, { text: doc.text, className: "doc-md doc-md-small" })
|
|
210
|
+
: _jsx("p", { className: "doc-empty-preview", children: "Nothing written yet." })] }));
|
|
211
|
+
};
|