@copilotz/work 0.0.0-stage → 1.0.0-rc.34
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,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A document's page (kind `document`, at `/document/<id>`): the title in
|
|
3
|
+
* place, then the writing surface (editor.tsx: Write, Preview or Split),
|
|
4
|
+
* for those who may change it; for those who may only read it (viewers, an
|
|
5
|
+
* archived space), the document as it reads.
|
|
6
|
+
*
|
|
7
|
+
* - **Saving** is explicit: ⌘S (Ctrl+S) or Save, each one a version. What's
|
|
8
|
+
* unsaved says so, honestly, and is kept in the browser as you type, so a
|
|
9
|
+
* closed tab loses nothing (it's there, and said, next time).
|
|
10
|
+
* - **Live:** others' saves come in at once. With nothing unsaved, the page
|
|
11
|
+
* takes them; with something, it says who saved what, and whether saving
|
|
12
|
+
* will merge (changes to other lines) or clash (the same lines), and lets
|
|
13
|
+
* the person settle it before they save.
|
|
14
|
+
* - **Who's here:** others with it open, and who's editing, in its header.
|
|
15
|
+
* - **A clash** on saving (`conflict`): the conflict screen (conflict.tsx).
|
|
16
|
+
* - **History** (a drawer, history.tsx): every version, its changes, and
|
|
17
|
+
* restoring one. Copying its link, downloading its Markdown, deleting it,
|
|
18
|
+
* from its menu.
|
|
19
|
+
*/
|
|
20
|
+
import { type ReactNode } from "react";
|
|
21
|
+
import type { ViewContext } from "copilotz";
|
|
22
|
+
import type { Document } from "../../contract.js";
|
|
23
|
+
import { type Call } from "./people.js";
|
|
24
|
+
export declare const documentView: (item: {
|
|
25
|
+
_id?: string;
|
|
26
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
27
|
+
/** Deleting a document, once they've read what it means. */
|
|
28
|
+
export declare function DeleteDialog({ open, onClose, doc, where, call, deleted }: {
|
|
29
|
+
open: boolean;
|
|
30
|
+
onClose(): void;
|
|
31
|
+
doc: Pick<Document, "_id" | "title" | "version">;
|
|
32
|
+
where: string;
|
|
33
|
+
call: Call;
|
|
34
|
+
deleted?(): void;
|
|
35
|
+
}): ReactNode;
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A document's page (kind `document`, at `/document/<id>`): the title in
|
|
4
|
+
* place, then the writing surface (editor.tsx: Write, Preview or Split),
|
|
5
|
+
* for those who may change it; for those who may only read it (viewers, an
|
|
6
|
+
* archived space), the document as it reads.
|
|
7
|
+
*
|
|
8
|
+
* - **Saving** is explicit: ⌘S (Ctrl+S) or Save, each one a version. What's
|
|
9
|
+
* unsaved says so, honestly, and is kept in the browser as you type, so a
|
|
10
|
+
* closed tab loses nothing (it's there, and said, next time).
|
|
11
|
+
* - **Live:** others' saves come in at once. With nothing unsaved, the page
|
|
12
|
+
* takes them; with something, it says who saved what, and whether saving
|
|
13
|
+
* will merge (changes to other lines) or clash (the same lines), and lets
|
|
14
|
+
* the person settle it before they save.
|
|
15
|
+
* - **Who's here:** others with it open, and who's editing, in its header.
|
|
16
|
+
* - **A clash** on saving (`conflict`): the conflict screen (conflict.tsx).
|
|
17
|
+
* - **History** (a drawer, history.tsx): every version, its changes, and
|
|
18
|
+
* restoring one. Copying its link, downloading its Markdown, deleting it,
|
|
19
|
+
* from its menu.
|
|
20
|
+
*/
|
|
21
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
22
|
+
import { Badge, Button, Dialog, Drawer, EmptyState, go, Icon, Kbd, keep, kept, LazyView, Menu, message, Notice, Page, Skeleton, Spinner, Time, Title, Tooltip, } from "copilotz/web";
|
|
23
|
+
import { merge, mergeField } from "../../shared/merge.js";
|
|
24
|
+
import { documentsTab, kb, UNTITLED } from "../../shared/text.js";
|
|
25
|
+
import { Conflict } from "./conflict.js";
|
|
26
|
+
import { Diff } from "./changes.js";
|
|
27
|
+
import { draftOf, dropDraft, keepDraft } from "./draft.js";
|
|
28
|
+
import { Editor, Glyph, Toolbar, useWide } from "./editor.js";
|
|
29
|
+
import { wordsIn } from "./format.js";
|
|
30
|
+
import { RESTORED } from "./history.js";
|
|
31
|
+
import { count, MOD, modded, placeName, said, shownAs, useNow, whoIn, writes, } from "./people.js";
|
|
32
|
+
import { hereNow, named, Present, usePresence } from "./presence.js";
|
|
33
|
+
import { STYLE } from "./style.js";
|
|
34
|
+
const style = _jsx("style", { href: "documents-web", precedence: "copilotz", children: STYLE });
|
|
35
|
+
export const documentView = (item, ctx) => {
|
|
36
|
+
const id = item._id ?? "";
|
|
37
|
+
const query = (ctx.hints.query ?? {});
|
|
38
|
+
const doc = ctx.db.collection("document").findOne({ _id: id }).value;
|
|
39
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
40
|
+
const presence = ctx.db.collection("documentPresence").find({ document: id }).value;
|
|
41
|
+
const known = whoIn(ctx, [
|
|
42
|
+
doc?.savedBy,
|
|
43
|
+
doc?.createdBy,
|
|
44
|
+
doc?.savedFor,
|
|
45
|
+
...(presence ?? []).map((p) => p.who),
|
|
46
|
+
]);
|
|
47
|
+
const me = ctx.viewer?.name ?? ctx.actor?.id;
|
|
48
|
+
if (doc === undefined || places === undefined) {
|
|
49
|
+
return (_jsxs(Page, { title: _jsx(Skeleton, { width: 260, height: 32 }), children: [style, _jsxs("div", { className: "doc-loading", "aria-busy": "true", children: [_jsx(Skeleton, { height: 18, width: "40%" }), _jsx(Skeleton, { height: 40, radius: "lg" }), _jsx(Skeleton, { height: 320, radius: "xl" })] })] }));
|
|
50
|
+
}
|
|
51
|
+
if (!doc)
|
|
52
|
+
return _jsx(Missing, { id: id, me: me });
|
|
53
|
+
const place = places.find((p) => p._id === doc.in);
|
|
54
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(DocumentPage, { doc: doc, place: place, me: me, presence: presence ?? [], known: known, query: query, call: ctx.call }, id)] }));
|
|
55
|
+
};
|
|
56
|
+
function DocumentPage({ doc, place, me, presence, known, query, call }) {
|
|
57
|
+
const viewer = me ?? "";
|
|
58
|
+
const write = writes(place);
|
|
59
|
+
const where = place ? placeName(place) : "its space";
|
|
60
|
+
const shown = (key) => shownAs(key, known);
|
|
61
|
+
const field = useRef(null);
|
|
62
|
+
const titleField = useRef(null);
|
|
63
|
+
const [page] = useState(() => crypto.randomUUID().slice(0, 18));
|
|
64
|
+
// What was left unsaved here last time, if it's still unsaved.
|
|
65
|
+
const [kept0] = useState(() => {
|
|
66
|
+
const d = write ? draftOf(viewer, doc._id) : undefined;
|
|
67
|
+
if (d && d.text === doc.text && d.title === doc.title) {
|
|
68
|
+
dropDraft(viewer, doc._id);
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return d && (d.text !== d.baseText || d.title !== d.baseTitle) ? d : undefined;
|
|
72
|
+
});
|
|
73
|
+
const [base, setBase] = useState(() => kept0
|
|
74
|
+
? { version: kept0.base, text: kept0.baseText, title: kept0.baseTitle }
|
|
75
|
+
: { version: doc.version, text: doc.text, title: doc.title });
|
|
76
|
+
const [text, setText] = useState(() => kept0?.text ?? doc.text);
|
|
77
|
+
const [title, setTitle] = useState(() => kept0?.title ?? doc.title);
|
|
78
|
+
const [restoredDraft, setRestoredDraft] = useState(kept0?.at);
|
|
79
|
+
const [saving, setSaving] = useState(false);
|
|
80
|
+
const [error, setError] = useState();
|
|
81
|
+
const [flash, setFlash] = useState();
|
|
82
|
+
const [conflict, setConflict] = useState();
|
|
83
|
+
const [conflictError, setConflictError] = useState();
|
|
84
|
+
const [aside, setAside] = useState();
|
|
85
|
+
const [showHistory, setHistory] = useState(query.history === "1");
|
|
86
|
+
const [deleting, setDeleting] = useState(false);
|
|
87
|
+
const [theirsOpen, setTheirsOpen] = useState(false);
|
|
88
|
+
const wide = useWide();
|
|
89
|
+
const [mode, setModeState] = useState(() => {
|
|
90
|
+
const k = kept(`copilotz-document-mode:${viewer}`);
|
|
91
|
+
return k === "preview" || k === "split" ? k : "write";
|
|
92
|
+
});
|
|
93
|
+
const setMode = (m) => {
|
|
94
|
+
setModeState(m);
|
|
95
|
+
keep(`copilotz-document-mode:${viewer}`, m);
|
|
96
|
+
};
|
|
97
|
+
const shownMode = !write ? "preview" : mode === "split" && !wide ? "write" : mode;
|
|
98
|
+
const dirty = text !== base.text || title !== base.title;
|
|
99
|
+
const behind = doc.version > base.version;
|
|
100
|
+
const latest = useRef({ text, title, base, dirty, saving });
|
|
101
|
+
// A save in flight, known at once (state is known on the next render).
|
|
102
|
+
const inFlight = useRef(false);
|
|
103
|
+
latest.current = { text, title, base, dirty, saving };
|
|
104
|
+
// Others' saves: taken at once when nothing's unsaved here; otherwise said, below.
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const now = latest.current;
|
|
107
|
+
if (doc.version === now.base.version || now.saving || inFlight.current)
|
|
108
|
+
return;
|
|
109
|
+
if (!now.dirty && !conflict) {
|
|
110
|
+
setBase({ version: doc.version, text: doc.text, title: doc.title });
|
|
111
|
+
setText(doc.text);
|
|
112
|
+
setTitle(doc.title);
|
|
113
|
+
if (doc.version > now.base.version && doc.savedBy !== `person:${viewer}`) {
|
|
114
|
+
setFlash({ tone: "info", text: `${shown(doc.savedBy).name} saved version ${doc.version}` });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, [doc.version]);
|
|
118
|
+
// What's unsaved is kept in this browser as it's written.
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!write)
|
|
121
|
+
return;
|
|
122
|
+
const timer = setTimeout(() => {
|
|
123
|
+
if (dirty) {
|
|
124
|
+
keepDraft(viewer, doc._id, {
|
|
125
|
+
base: base.version,
|
|
126
|
+
baseText: base.text,
|
|
127
|
+
baseTitle: base.title,
|
|
128
|
+
text,
|
|
129
|
+
title,
|
|
130
|
+
at: new Date().toISOString(),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
dropDraft(viewer, doc._id);
|
|
135
|
+
}, 250);
|
|
136
|
+
return () => clearTimeout(timer);
|
|
137
|
+
}, [text, title, base, write]);
|
|
138
|
+
// Leaving with something unsaved: the browser asks (it's kept here anyway).
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!dirty)
|
|
141
|
+
return;
|
|
142
|
+
const ask = (event) => event.preventDefault();
|
|
143
|
+
globalThis.addEventListener("beforeunload", ask);
|
|
144
|
+
return () => globalThis.removeEventListener("beforeunload", ask);
|
|
145
|
+
}, [dirty]);
|
|
146
|
+
// A moment's note under the title, then it goes.
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (!flash)
|
|
149
|
+
return;
|
|
150
|
+
const timer = setTimeout(() => setFlash(undefined), 4000);
|
|
151
|
+
return () => clearTimeout(timer);
|
|
152
|
+
}, [flash]);
|
|
153
|
+
// ⌘S anywhere on the page saves.
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (!write)
|
|
156
|
+
return;
|
|
157
|
+
const pressed = (event) => {
|
|
158
|
+
if (modded(event) && !event.altKey && !event.shiftKey && event.key.toLowerCase() === "s") {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
void save();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
globalThis.addEventListener("keydown", pressed);
|
|
164
|
+
return () => globalThis.removeEventListener("keydown", pressed);
|
|
165
|
+
});
|
|
166
|
+
// A version restored from History: the drawer closes, and the page says so.
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
const restored = (event) => {
|
|
169
|
+
const { document, from, version } = event.detail ?? {};
|
|
170
|
+
if (document !== doc._id)
|
|
171
|
+
return;
|
|
172
|
+
setHistory(false);
|
|
173
|
+
setFlash({ tone: "success", text: `Brought back version ${from}, as version ${version}` });
|
|
174
|
+
};
|
|
175
|
+
globalThis.addEventListener(RESTORED, restored);
|
|
176
|
+
return () => globalThis.removeEventListener(RESTORED, restored);
|
|
177
|
+
}, [doc._id]);
|
|
178
|
+
// Just made (`?new=1`): its title, ready to type over.
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (query.new !== "1")
|
|
181
|
+
return;
|
|
182
|
+
if (write) {
|
|
183
|
+
titleField.current?.focus();
|
|
184
|
+
titleField.current?.select();
|
|
185
|
+
}
|
|
186
|
+
// Once: the address forgets it, so coming back doesn't select the title again.
|
|
187
|
+
const url = new URL(location.href);
|
|
188
|
+
url.searchParams.delete("new");
|
|
189
|
+
globalThis.history.replaceState(globalThis.history.state, "", url);
|
|
190
|
+
}, []);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (query.history === "1")
|
|
193
|
+
setHistory(true);
|
|
194
|
+
}, [query.history]);
|
|
195
|
+
usePresence(call, doc._id, page, dirty ? "editing" : "open", true);
|
|
196
|
+
const now = useNow(15_000);
|
|
197
|
+
const here = hereNow(presence, now, me, shown);
|
|
198
|
+
const editingToo = here.filter((h) => h.editing);
|
|
199
|
+
// Before saving: would it merge with what's been saved since, or clash?
|
|
200
|
+
const ahead = useMemo(() => {
|
|
201
|
+
if (!behind || !dirty || conflict)
|
|
202
|
+
return undefined;
|
|
203
|
+
const lines = merge(base.text, text, doc.text);
|
|
204
|
+
const titles = mergeField(base.title, title, doc.title);
|
|
205
|
+
return { clash: lines.conflicts > 0 || titles === undefined };
|
|
206
|
+
}, [behind, dirty, conflict, base.text, base.title, text, title, doc.text, doc.title]);
|
|
207
|
+
/** Saves what's written (or `what`, over the version `from`), and takes what it came to. */
|
|
208
|
+
async function save(what, from) {
|
|
209
|
+
const now = latest.current;
|
|
210
|
+
if (inFlight.current || (!what && !now.dirty))
|
|
211
|
+
return;
|
|
212
|
+
inFlight.current = true;
|
|
213
|
+
const sent = what ?? { text: now.text, title: now.title };
|
|
214
|
+
const sentBase = from ?? now.base.version;
|
|
215
|
+
setSaving(true);
|
|
216
|
+
setError(undefined);
|
|
217
|
+
setConflictError(undefined);
|
|
218
|
+
try {
|
|
219
|
+
const done = await call("document.save", {
|
|
220
|
+
document: doc._id,
|
|
221
|
+
base: sentBase,
|
|
222
|
+
text: sent.text,
|
|
223
|
+
title: sent.title,
|
|
224
|
+
});
|
|
225
|
+
const saved = { text: done.text ?? sent.text, title: done.title ?? sent.title };
|
|
226
|
+
setBase({ version: done.version, ...saved });
|
|
227
|
+
if (what) {
|
|
228
|
+
// Settled on the conflict screen: what was saved is what's written now.
|
|
229
|
+
setText(saved.text);
|
|
230
|
+
setTitle(saved.title);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Typed while it saved: kept, on top of what was saved.
|
|
234
|
+
setText((cur) => cur === sent.text ? saved.text : merge(sent.text, cur, saved.text).text ?? cur);
|
|
235
|
+
setTitle((cur) => cur === sent.title ? saved.title : cur);
|
|
236
|
+
}
|
|
237
|
+
setConflict(undefined);
|
|
238
|
+
setAside(undefined);
|
|
239
|
+
setRestoredDraft(undefined);
|
|
240
|
+
setFlash(done.unchanged ? { tone: "info", text: "Nothing new to save" } : done.merged
|
|
241
|
+
? {
|
|
242
|
+
tone: "success",
|
|
243
|
+
text: `Merged with ${shown(doc.savedBy).name}'s changes · version ${done.version}`,
|
|
244
|
+
}
|
|
245
|
+
: { tone: "success", text: `Saved version ${done.version}` });
|
|
246
|
+
if (!done.unchanged)
|
|
247
|
+
dropDraft(viewer, doc._id);
|
|
248
|
+
}
|
|
249
|
+
catch (e) {
|
|
250
|
+
const code = e?.code;
|
|
251
|
+
if (code === "conflict") {
|
|
252
|
+
setConflict({ base: now.base, mine: sent });
|
|
253
|
+
setConflictError(what ? message(e) : undefined);
|
|
254
|
+
}
|
|
255
|
+
else if (what)
|
|
256
|
+
setConflictError(message(e));
|
|
257
|
+
else
|
|
258
|
+
setError(message(e));
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
inFlight.current = false;
|
|
262
|
+
setSaving(false);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const theirs = {
|
|
266
|
+
text: doc.text,
|
|
267
|
+
title: doc.title,
|
|
268
|
+
version: doc.version,
|
|
269
|
+
at: doc.savedAt,
|
|
270
|
+
by: shown(doc.savedBy),
|
|
271
|
+
};
|
|
272
|
+
const savedBy = shown(doc.savedBy);
|
|
273
|
+
const savedFor = doc.savedFor ? shown(doc.savedFor) : undefined;
|
|
274
|
+
const copyLink = () => void navigator.clipboard?.writeText(`${location.origin}/document/${doc._id}`).then(() => setFlash({ tone: "success", text: "Link copied" }));
|
|
275
|
+
const download = () => {
|
|
276
|
+
const url = URL.createObjectURL(new Blob([text], { type: "text/markdown" }));
|
|
277
|
+
const a = Object.assign(document.createElement("a"), {
|
|
278
|
+
href: url,
|
|
279
|
+
download: `${(title || UNTITLED).replace(/[\\/:*?"<>|]+/g, " ").trim()}.md`,
|
|
280
|
+
});
|
|
281
|
+
a.click();
|
|
282
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
283
|
+
};
|
|
284
|
+
const more = [
|
|
285
|
+
{ label: "History", icon: "retry", onSelect: () => setHistory(true) },
|
|
286
|
+
{ label: "Copy link", icon: "copy", onSelect: copyLink },
|
|
287
|
+
{ label: "Download Markdown", icon: "download", onSelect: download },
|
|
288
|
+
...(write && dirty
|
|
289
|
+
? [{
|
|
290
|
+
label: "Discard unsaved changes",
|
|
291
|
+
icon: "close",
|
|
292
|
+
onSelect: () => {
|
|
293
|
+
setAside({ text, title });
|
|
294
|
+
setBase({ version: doc.version, text: doc.text, title: doc.title });
|
|
295
|
+
setText(doc.text);
|
|
296
|
+
setTitle(doc.title);
|
|
297
|
+
setRestoredDraft(undefined);
|
|
298
|
+
},
|
|
299
|
+
}]
|
|
300
|
+
: []),
|
|
301
|
+
...(place
|
|
302
|
+
? [{ label: `${where}'s documents`, icon: "file", href: documentsTab(place._id) }]
|
|
303
|
+
: []),
|
|
304
|
+
...(write
|
|
305
|
+
? [
|
|
306
|
+
"separator",
|
|
307
|
+
{
|
|
308
|
+
label: "Delete…",
|
|
309
|
+
icon: "trash",
|
|
310
|
+
tone: "destructive",
|
|
311
|
+
onSelect: () => setDeleting(true),
|
|
312
|
+
},
|
|
313
|
+
]
|
|
314
|
+
: []),
|
|
315
|
+
];
|
|
316
|
+
const status = saving
|
|
317
|
+
? (_jsxs("span", { className: "doc-status", "data-state": "saving", children: [_jsx(Spinner, { size: 12 }), " Saving\u2026"] }))
|
|
318
|
+
: error
|
|
319
|
+
? (_jsxs("span", { className: "doc-status", "data-state": "failed", children: [_jsx(Icon, { name: "alert", size: 13 }), " Couldn't save: ", error, _jsx(Button, { variant: "link", size: "sm", onClick: () => void save(), children: "Try again" })] }))
|
|
320
|
+
: flash
|
|
321
|
+
? (_jsxs("span", { className: "doc-status", "data-state": flash.tone, children: [_jsx(Icon, { name: flash.tone === "success" ? "check" : "info", size: 13 }), " ", flash.text] }))
|
|
322
|
+
: dirty
|
|
323
|
+
? (_jsxs("span", { className: "doc-status", "data-state": "dirty", children: [_jsx("span", { className: "doc-dot", "aria-hidden": "true" }), " Unsaved changes", _jsxs("span", { className: "doc-status-quiet", children: ["\u00B7 ", _jsx(Kbd, { children: MOD }), _jsx(Kbd, { children: "S" }), " to save"] })] }))
|
|
324
|
+
: (_jsxs("span", { className: "doc-status", children: ["Version ", doc.version, " \u00B7 ", said(savedBy, me), savedFor ? ` for ${said(savedFor, me, false)}` : "", " \u00B7 ", _jsx(Time, { at: doc.savedAt })] }));
|
|
325
|
+
const titleInput = write
|
|
326
|
+
? (_jsx("span", { className: "doc-title-grow", "data-value": `${title || UNTITLED} `, children: _jsx("textarea", { ref: titleField, className: "doc-title-input", rows: 1, value: title, placeholder: UNTITLED, "aria-label": "Title", maxLength: 200, spellCheck: true, onChange: (event) => setTitle(event.target.value.replace(/\n/g, " ")), onKeyDown: (event) => {
|
|
327
|
+
if (event.key === "Enter") {
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
field.current?.focus();
|
|
330
|
+
}
|
|
331
|
+
} }) }))
|
|
332
|
+
: doc.title;
|
|
333
|
+
return (_jsxs(Page, { className: "doc-page", width: shownMode === "split" ? "full" : "md", title: titleInput, back: place ? { href: documentsTab(place._id), label: `${where} · Documents` } : undefined, badges: !write
|
|
334
|
+
? _jsx(Badge, { variant: "outline", children: place?.archived ? "Archived" : "View only" })
|
|
335
|
+
: null, description: _jsxs("span", { className: "doc-under", role: "status", "aria-live": "polite", children: [status, editingToo.length && dirty
|
|
336
|
+
? (_jsxs("span", { className: "doc-status", "data-state": "warning", children: [_jsx(Icon, { name: "pencil", size: 12 }), " ", named(editingToo), " ", editingToo.length === 1 ? "is" : "are", " editing too"] }))
|
|
337
|
+
: null] }), actions: _jsxs(_Fragment, { children: [_jsx(Present, { here: here }), _jsx(Tooltip, { text: "Every version, and what changed", describe: false, children: _jsxs(Button, { variant: "ghost", className: "doc-history-button", "aria-label": "History", onClick: () => setHistory(true), children: [_jsx(Glyph, { name: "history" }), _jsx("span", { className: "doc-wide", children: "History" })] }) }), write
|
|
338
|
+
? (_jsx(Tooltip, { text: _jsxs(_Fragment, { children: ["Save a version ", _jsx(Kbd, { children: MOD }), _jsx(Kbd, { children: "S" })] }), describe: false, children: _jsx(Button, { variant: dirty && !conflict ? "primary" : "outline", className: "doc-save", loading: saving, disabled: !dirty || !!conflict, onClick: () => void save(), children: dirty || saving ? "Save" : "Saved" }) }))
|
|
339
|
+
: null, _jsx(Menu, { label: "This document: more", align: "end", items: more })] }), children: [_jsx(Title, { text: doc.title }), _jsxs("div", { className: "doc-body", children: [restoredDraft && dirty && !conflict
|
|
340
|
+
? (_jsxs(Notice, { tone: "info", icon: "refresh", className: "doc-banner", action: _jsx(Button, { size: "sm", variant: "ghost", onClick: () => {
|
|
341
|
+
setRestoredDraft(undefined);
|
|
342
|
+
setBase({ version: doc.version, text: doc.text, title: doc.title });
|
|
343
|
+
setText(doc.text);
|
|
344
|
+
setTitle(doc.title);
|
|
345
|
+
dropDraft(viewer, doc._id);
|
|
346
|
+
}, children: "Discard them" }), children: ["Your unsaved changes from ", _jsx(Time, { at: restoredDraft, long: true }), " are back, as you left them."] }))
|
|
347
|
+
: null, aside
|
|
348
|
+
? (_jsx(Notice, { tone: "neutral", icon: "restore", className: "doc-banner", action: _jsx(Button, { size: "sm", variant: "ghost", onClick: () => {
|
|
349
|
+
setText(aside.text);
|
|
350
|
+
setTitle(aside.title);
|
|
351
|
+
setAside(undefined);
|
|
352
|
+
}, children: "Bring mine back" }), children: "Your changes are put aside." }))
|
|
353
|
+
: null, ahead
|
|
354
|
+
? (_jsxs(Notice, { tone: ahead.clash ? "warning" : "info", icon: ahead.clash ? "alert" : "info", className: "doc-banner", action: _jsxs("span", { className: "doc-banner-actions", children: [_jsx(Button, { size: "sm", variant: "ghost", onClick: () => setTheirsOpen(true), children: "What they changed" }), ahead.clash
|
|
355
|
+
? (_jsx(Button, { size: "sm", onClick: () => setConflict({ base, mine: { text, title } }), children: "Settle it now" }))
|
|
356
|
+
: null] }), children: [_jsx("b", { children: theirs.by.name }), " saved version ", doc.version, " while you were writing.", " ", ahead.clash
|
|
357
|
+
? "Some of the same lines changed: saving will ask you which to keep."
|
|
358
|
+
: "None of the same lines: saving keeps both."] }))
|
|
359
|
+
: null, conflict
|
|
360
|
+
? (_jsx(Conflict, { base: conflict.base, mine: conflict.mine, theirs: theirs, busy: saving, error: conflictError, onKeep: () => void save(conflict.mine, doc.version), onTake: () => {
|
|
361
|
+
setAside(conflict.mine);
|
|
362
|
+
setBase({ version: doc.version, text: doc.text, title: doc.title });
|
|
363
|
+
setText(doc.text);
|
|
364
|
+
setTitle(doc.title);
|
|
365
|
+
setConflict(undefined);
|
|
366
|
+
setFlash({ tone: "info", text: `Took ${theirs.by.name}'s version ${doc.version}` });
|
|
367
|
+
}, onSave: (merged) => void save(merged, doc.version), onEdit: (merged) => {
|
|
368
|
+
setBase({ version: doc.version, text: doc.text, title: doc.title });
|
|
369
|
+
setText(merged.text);
|
|
370
|
+
setTitle(merged.title);
|
|
371
|
+
setConflict(undefined);
|
|
372
|
+
requestAnimationFrame(() => field.current?.focus());
|
|
373
|
+
} }))
|
|
374
|
+
: (_jsxs(_Fragment, { children: [write
|
|
375
|
+
? (_jsx("div", { className: "doc-bar", children: _jsx(Toolbar, { field: field, mode: shownMode, onMode: setMode, split: wide, editing: shownMode !== "preview" }) }))
|
|
376
|
+
: null, _jsx(Editor, { value: text, onChange: setText, field: field, mode: shownMode, placeholder: "Start writing. Markdown works: # a heading, - a list, **bold**, " +
|
|
377
|
+
"[a link](https://…)", label: "The document, in Markdown" }), _jsxs("footer", { className: "doc-foot", children: [_jsx("span", { children: count(wordsIn(text), "word") }), _jsx("span", { children: kb(new TextEncoder().encode(text).length) }), _jsxs("span", { children: ["Made by ", said(shown(doc.createdBy), me, false), " ", _jsx(Time, { at: doc.createdAt, long: true })] }), !write
|
|
378
|
+
? (_jsx("span", { children: place?.archived
|
|
379
|
+
? `${where} is archived: what's in it reads as it is.`
|
|
380
|
+
: `You can read this. Editors of ${where} can change it.` }))
|
|
381
|
+
: null] })] }))] }), _jsx(Drawer, { open: showHistory, onClose: () => setHistory(false), side: "right", title: `History · ${doc.title}`, className: "doc-history", children: showHistory
|
|
382
|
+
? _jsx(LazyView, { kind: "document.history", item: { _id: doc._id }, hints: { write } })
|
|
383
|
+
: null }), _jsx(Dialog, { open: theirsOpen, onClose: () => setTheirsOpen(false), size: "lg", title: `What ${theirs.by.name} changed`, description: `Since version ${base.version}, which you started from.`, children: theirsOpen ? _jsx(Diff, { before: base.text, after: doc.text }) : null }), write
|
|
384
|
+
? (_jsx(DeleteDialog, { open: deleting, onClose: () => setDeleting(false), doc: doc, where: where, call: call, deleted: () => {
|
|
385
|
+
dropDraft(viewer, doc._id);
|
|
386
|
+
go(place ? documentsTab(place._id) : "/");
|
|
387
|
+
} }))
|
|
388
|
+
: null] }));
|
|
389
|
+
}
|
|
390
|
+
/** Deleting a document, once they've read what it means. */
|
|
391
|
+
export function DeleteDialog({ open, onClose, doc, where, call, deleted }) {
|
|
392
|
+
const [busy, setBusy] = useState(false);
|
|
393
|
+
const [error, setError] = useState();
|
|
394
|
+
return (_jsx(Dialog, { open: open, onClose: onClose, size: "sm", title: `Delete “${doc.title}”?`, description: `It goes for everyone in ${where}, with its ${count(doc.version, "version")}. This can't be undone.`, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: onClose, disabled: busy, children: "Keep it" }), _jsx(Button, { variant: "destructive", icon: "trash", loading: busy, onClick: async () => {
|
|
395
|
+
setBusy(true);
|
|
396
|
+
setError(undefined);
|
|
397
|
+
try {
|
|
398
|
+
await call("document.delete", { document: doc._id });
|
|
399
|
+
onClose();
|
|
400
|
+
deleted?.();
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
setError(message(e));
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
setBusy(false);
|
|
407
|
+
}
|
|
408
|
+
}, children: "Delete document" })] }), children: error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null }));
|
|
409
|
+
}
|
|
410
|
+
/** A document that isn't there: gone, or somewhere the person isn't; with their draft, if any. */
|
|
411
|
+
function Missing({ id, me }) {
|
|
412
|
+
const draft = me ? draftOf(me, id) : undefined;
|
|
413
|
+
return (_jsxs("div", { className: "doc-missing", children: [style, _jsx(Title, { text: "No such document" }), _jsx(EmptyState, { icon: "file", heading: "h1", title: "This document isn't here", action: _jsx(Button, { variant: "primary", icon: "home", href: "/", children: "Go home" }), children: "It may have been deleted, or it's in a space you're not in." }), draft
|
|
414
|
+
? (_jsxs(Notice, { tone: "warning", title: "You had unsaved changes in it", action: _jsx(Button, { size: "sm", icon: "copy", onClick: () => void navigator.clipboard?.writeText(draft.text), children: "Copy them" }), children: ["\u201C", draft.title, "\u201D, ", count(wordsIn(draft.text), "word"), ": copy them before you go."] }))
|
|
415
|
+
: null] }));
|
|
416
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What documents offer in the command palette (kind `document.palette`, the
|
|
3
|
+
* web shell's `palette` resource), for where the person is and what's typed:
|
|
4
|
+
*
|
|
5
|
+
* - **This document**, on a document's page: its History, its link, its
|
|
6
|
+
* Markdown, renaming it and deleting it (those who may change it), and its
|
|
7
|
+
* space's documents;
|
|
8
|
+
* - **This space:** its Documents tab;
|
|
9
|
+
* - **Documents**, while searching: the latest anywhere the person reaches,
|
|
10
|
+
* to go to;
|
|
11
|
+
* - **Create:** a new document where they are, named as they type.
|
|
12
|
+
*/
|
|
13
|
+
import type { ReactNode } from "react";
|
|
14
|
+
import type { ViewContext } from "copilotz";
|
|
15
|
+
import { type PaletteGroup } from "copilotz/web";
|
|
16
|
+
export declare const documentsPaletteView: (_: unknown, ctx: ViewContext<ReactNode>) => PaletteGroup[] | null;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { go } from "copilotz/web";
|
|
2
|
+
import { documentPath, documentsTab, TITLE } from "../../shared/text.js";
|
|
3
|
+
import { newDocument, renameStep } from "./list.js";
|
|
4
|
+
import { placeName, writes } from "./people.js";
|
|
5
|
+
/** Deleting a document, once they've read what it means; then its space's documents. */
|
|
6
|
+
const deleteStep = (doc, call) => ({
|
|
7
|
+
title: `Delete “${doc.title}”?`,
|
|
8
|
+
confirm: true,
|
|
9
|
+
note: `It goes for everyone in its space, with its ${doc.version} version${doc.version === 1 ? "" : "s"}. This can't be undone.`,
|
|
10
|
+
items: () => [{
|
|
11
|
+
title: "",
|
|
12
|
+
items: [
|
|
13
|
+
{
|
|
14
|
+
key: "document:delete",
|
|
15
|
+
label: `Delete “${doc.title}”`,
|
|
16
|
+
icon: "trash",
|
|
17
|
+
tone: "destructive",
|
|
18
|
+
run: async () => {
|
|
19
|
+
await call("document.delete", { document: doc._id });
|
|
20
|
+
go(documentsTab(doc.in));
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{ key: "document:keep", label: "Keep it", icon: "close", run: (p) => p.back() },
|
|
24
|
+
],
|
|
25
|
+
}],
|
|
26
|
+
});
|
|
27
|
+
/** Naming a new document in `space`, then opening it. */
|
|
28
|
+
const newStep = (space, where, call) => ({
|
|
29
|
+
title: `New document in ${where}`,
|
|
30
|
+
placeholder: "Its title (or name it later)",
|
|
31
|
+
filter: false,
|
|
32
|
+
items: (search) => {
|
|
33
|
+
const title = search.trim();
|
|
34
|
+
const long = title.length > TITLE;
|
|
35
|
+
return [{
|
|
36
|
+
title: "",
|
|
37
|
+
items: [{
|
|
38
|
+
key: "document:create",
|
|
39
|
+
label: title ? `Create “${title}”` : "Create an untitled document",
|
|
40
|
+
icon: "plus",
|
|
41
|
+
disabled: long,
|
|
42
|
+
...(long ? { description: `At most ${TITLE} characters` } : {}),
|
|
43
|
+
run: () => newDocument(call, space, title ? { title } : undefined),
|
|
44
|
+
}],
|
|
45
|
+
}];
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
export const documentsPaletteView = (_, ctx) => {
|
|
49
|
+
const searching = !!String(ctx.hints.search ?? "").trim();
|
|
50
|
+
const page = (ctx.hints.page ?? {});
|
|
51
|
+
const open = page.kind === "document" && page.id
|
|
52
|
+
? ctx.db.collection("document").findOne({ _id: page.id }).value
|
|
53
|
+
: null;
|
|
54
|
+
const here = typeof ctx.hints.in === "string" ? ctx.hints.in : open?.in;
|
|
55
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
56
|
+
const recent = searching
|
|
57
|
+
? ctx.db.collection("document").query("recent", { limit: 50 }).value
|
|
58
|
+
: [];
|
|
59
|
+
if (!places || open === undefined || !recent)
|
|
60
|
+
return null;
|
|
61
|
+
const place = places.find((p) => p._id === here);
|
|
62
|
+
const groups = [];
|
|
63
|
+
if (open) {
|
|
64
|
+
const home = places.find((p) => p._id === open.in);
|
|
65
|
+
const write = writes(home);
|
|
66
|
+
const items = [
|
|
67
|
+
{
|
|
68
|
+
key: "document:history",
|
|
69
|
+
label: "History",
|
|
70
|
+
icon: "retry",
|
|
71
|
+
keywords: ["versions", "changes", "diff", "restore"],
|
|
72
|
+
href: `${documentPath(open._id, open.in)}&history=1`,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: "document:link",
|
|
76
|
+
label: "Copy link",
|
|
77
|
+
icon: "copy",
|
|
78
|
+
keywords: ["share", "url"],
|
|
79
|
+
run: () => navigator.clipboard?.writeText(`${location.origin}/document/${open._id}`),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: "document:download",
|
|
83
|
+
label: "Download Markdown",
|
|
84
|
+
icon: "download",
|
|
85
|
+
keywords: ["export", "md", "file"],
|
|
86
|
+
run: () => {
|
|
87
|
+
const url = URL.createObjectURL(new Blob([open.text], { type: "text/markdown" }));
|
|
88
|
+
Object.assign(document.createElement("a"), { href: url, download: `${open.title}.md` })
|
|
89
|
+
.click();
|
|
90
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
...(write
|
|
94
|
+
? [{
|
|
95
|
+
key: "document:rename",
|
|
96
|
+
label: `Rename “${open.title}”…`,
|
|
97
|
+
icon: "pencil",
|
|
98
|
+
keywords: ["title"],
|
|
99
|
+
step: renameStep(open, ctx.call),
|
|
100
|
+
}]
|
|
101
|
+
: []),
|
|
102
|
+
...(home
|
|
103
|
+
? [{
|
|
104
|
+
key: "document:all",
|
|
105
|
+
label: `${placeName(home)}'s documents`,
|
|
106
|
+
icon: "file",
|
|
107
|
+
href: documentsTab(home._id),
|
|
108
|
+
}]
|
|
109
|
+
: []),
|
|
110
|
+
...(write
|
|
111
|
+
? [{
|
|
112
|
+
key: "document:delete-step",
|
|
113
|
+
label: `Delete “${open.title}”…`,
|
|
114
|
+
icon: "trash",
|
|
115
|
+
tone: "destructive",
|
|
116
|
+
step: deleteStep(open, ctx.call),
|
|
117
|
+
}]
|
|
118
|
+
: []),
|
|
119
|
+
];
|
|
120
|
+
// What's open comes first: before its space's.
|
|
121
|
+
groups.push({ title: "This document", order: 8, items });
|
|
122
|
+
}
|
|
123
|
+
else if (here && place) {
|
|
124
|
+
groups.push({
|
|
125
|
+
title: "This space",
|
|
126
|
+
order: 10,
|
|
127
|
+
items: [{
|
|
128
|
+
key: "document:tab",
|
|
129
|
+
label: "Documents",
|
|
130
|
+
icon: "file",
|
|
131
|
+
description: "Plans, drafts and decisions",
|
|
132
|
+
keywords: ["documents", "docs", "notes", "writing", "markdown"],
|
|
133
|
+
href: documentsTab(here),
|
|
134
|
+
}],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (searching && recent.length) {
|
|
138
|
+
const names = new Map(places.map((p) => [p._id, placeName(p)]));
|
|
139
|
+
groups.push({
|
|
140
|
+
title: "Documents",
|
|
141
|
+
order: 32,
|
|
142
|
+
limit: 6,
|
|
143
|
+
items: recent.map((d) => ({
|
|
144
|
+
key: `document:${d._id}`,
|
|
145
|
+
label: d.title,
|
|
146
|
+
icon: "file",
|
|
147
|
+
description: names.get(d.in) ?? "",
|
|
148
|
+
keywords: [d.excerpt.slice(0, 160)],
|
|
149
|
+
href: documentPath(d._id, d.in),
|
|
150
|
+
})),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (here && place && writes(place)) {
|
|
154
|
+
groups.push({
|
|
155
|
+
title: "Create",
|
|
156
|
+
order: 40,
|
|
157
|
+
items: [{
|
|
158
|
+
key: "document:new",
|
|
159
|
+
label: "New document…",
|
|
160
|
+
icon: "file",
|
|
161
|
+
description: placeName(place),
|
|
162
|
+
keywords: ["document", "doc", "write", "markdown", "page"],
|
|
163
|
+
step: newStep(here, placeName(place), ctx.call),
|
|
164
|
+
}],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return groups;
|
|
168
|
+
};
|