Add a timeline view to databases
Records are bars from the view's date property to an end date property (chosen in the view's settings; without one a bar lasts a day), by days, weeks or months. Dragging a bar moves both dates; its right edge changes the end. Records without a start are listed below, like on the calendar. Bars stop the browser's own drag of the surrounding block. Also fixes the view settings panel: the properties list cleared the whole panel when it drew, so a calendar never showed its date property. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ab73a7d0d7
commit
ff75ecd04c
25 files changed
+1028
-116
No files matched your search
@@ -9,6 +9,9 @@ What changed in each Docwell release. The release workflow copies a version's se
|
||||
- Two new database views: **list**, one line per record with its properties, and **gallery**, cards in a grid with a
|
||||
cover image from an attachment property. Both filter, sort and group like tables. Apps from before this release show
|
||||
these views as tables.
|
||||
- A **timeline** view: records as bars from a start date to an end date property, shown by days, weeks or months. Drag
|
||||
a bar to move it, or its right edge to change its end.
|
||||
- Fixed: the view settings of a calendar showed only its properties, not the date property to place records by.
|
||||
|
||||
### Email
|
||||
|
||||
|
||||
@@ -71,7 +71,9 @@ it together, and Ctrl+Z undoes database changes like any other.
|
||||
**table**, a **kanban** board grouped by a select, checkbox or member property (drag cards between columns), and a
|
||||
**calendar** that places records on a date property (drag them to another day), a **list** with one line per record,
|
||||
and a **gallery** of cards, covered with the first image of an attachment property you pick in the view's settings.
|
||||
Lists and galleries can be grouped like tables. Click the active tab to rename, duplicate, change or delete the view;
|
||||
Lists and galleries can be grouped like tables. A **timeline** draws each record as a bar from its date property to an
|
||||
end date property (both chosen in the view's settings; without an end, a bar lasts a day), by days, weeks or months:
|
||||
drag a bar to move both dates, or its right edge to change the end. Click the active tab to rename, duplicate, change or delete the view;
|
||||
which view you look at is yours alone. Apps older than a layout show it as a table.
|
||||
- **Records as pages:** **Open** on a record, or a click on a card, opens it beside the page, with its properties on
|
||||
top and room to write below. **Open as full page** (the arrow button) shows the record on its own, in the page's
|
||||
|
||||
@@ -117,7 +117,11 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node {
|
||||
case "checkbox":
|
||||
return h(
|
||||
"span",
|
||||
{ class: v === true ? "dw-db-check is-on" : "dw-db-check", role: "img", "aria-label": v === true ? l.checked : l.unchecked },
|
||||
{
|
||||
class: v === true ? "dw-db-check is-on" : "dw-db-check",
|
||||
role: "img",
|
||||
"aria-label": v === true ? l.checked : l.unchecked,
|
||||
},
|
||||
v === true ? icon("check", 13) : null,
|
||||
);
|
||||
case "select": {
|
||||
@@ -145,7 +149,11 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node {
|
||||
return h(
|
||||
"span",
|
||||
{ class: "dw-db-progress" },
|
||||
h("span", { class: "dw-db-progress__bar" }, h("span", { class: "dw-db-progress__fill", style: { width: `${pct}%` } })),
|
||||
h(
|
||||
"span",
|
||||
{ class: "dw-db-progress__bar" },
|
||||
h("span", { class: "dw-db-progress__fill", style: { width: `${pct}%` } }),
|
||||
),
|
||||
h("span", { class: "dw-db-progress__num" }, `${pct}%`),
|
||||
);
|
||||
}
|
||||
@@ -166,7 +174,12 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node {
|
||||
{ class: "dw-db-tags" },
|
||||
asList<Attachment>(v).map((f) => {
|
||||
const href = ctx.files ? ctx.files.resolve(f.src) : f.src;
|
||||
const a = h("a", { class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" }, icon("paperclip", 12), f.name);
|
||||
const a = h(
|
||||
"a",
|
||||
{ class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" },
|
||||
icon("paperclip", 12),
|
||||
f.name,
|
||||
);
|
||||
a.addEventListener("click", (e) => {
|
||||
if (!e.ctrlKey && !e.metaKey) e.preventDefault();
|
||||
});
|
||||
@@ -178,7 +191,14 @@ export function renderCell(ctx: DbContext, row: Row, col: Column): Node {
|
||||
return h(
|
||||
"span",
|
||||
{ class: "dw-db-tags" },
|
||||
asList<Person>(v).map((p) => h("span", { class: "dw-db-person" }, h("span", { class: "dw-db-person__dot" }, (p?.name || "?").slice(0, 1).toUpperCase()), p?.name ?? "")),
|
||||
asList<Person>(v).map((p) =>
|
||||
h(
|
||||
"span",
|
||||
{ class: "dw-db-person" },
|
||||
h("span", { class: "dw-db-person__dot" }, (p?.name || "?").slice(0, 1).toUpperCase()),
|
||||
p?.name ?? "",
|
||||
),
|
||||
),
|
||||
);
|
||||
case "relation":
|
||||
return renderRelation(ctx, row, col);
|
||||
@@ -220,7 +240,8 @@ export function editCell(ctx: DbContext, el: HTMLElement, row: Row, col: Column,
|
||||
opts.onDone(move);
|
||||
};
|
||||
if (inlineTypes.includes(col.type)) {
|
||||
const start = opts.initial ?? (col.type === "number" ? (asNumber(v)?.toString() ?? "") : typeof v === "string" ? v : "");
|
||||
const start =
|
||||
opts.initial ?? (col.type === "number" ? (asNumber(v)?.toString() ?? "") : typeof v === "string" ? v : "");
|
||||
let move: "down" | "right" | "left" | undefined;
|
||||
const input = textInput(start, {
|
||||
class: "dw-db-cell__input",
|
||||
@@ -272,7 +293,11 @@ export function editCell(ctx: DbContext, el: HTMLElement, row: Row, col: Column,
|
||||
const today = h("button", { type: "button", class: "dw-db__btn" }, ctx.labels.today);
|
||||
today.addEventListener("click", () => {
|
||||
const d = new Date();
|
||||
store.setCell(row.id, col.id, `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`);
|
||||
store.setCell(
|
||||
row.id,
|
||||
col.id,
|
||||
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`,
|
||||
);
|
||||
close();
|
||||
});
|
||||
box.append(input, h("div", { class: "dw-db-pop__row" }, today, clear));
|
||||
@@ -282,7 +307,14 @@ export function editCell(ctx: DbContext, el: HTMLElement, row: Row, col: Column,
|
||||
case "progress":
|
||||
panel((box, close) => {
|
||||
const n = asNumber(v) ?? 0;
|
||||
const range = h("input", { type: "range", min: "0", max: "100", step: "1", class: "dw-db-range", "aria-label": col.name });
|
||||
const range = h("input", {
|
||||
type: "range",
|
||||
min: "0",
|
||||
max: "100",
|
||||
step: "1",
|
||||
class: "dw-db-range",
|
||||
"aria-label": col.name,
|
||||
});
|
||||
range.value = String(n);
|
||||
const num = h("span", { class: "dw-db-progress__num" }, `${n}%`);
|
||||
range.addEventListener("input", () => (num.textContent = `${range.value}%`));
|
||||
@@ -314,7 +346,9 @@ function choicePanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Column,
|
||||
const l = ctx.labels;
|
||||
const multi = col.type === "multiSelect";
|
||||
let options: SelectOption[] = [...(col.options ?? [])];
|
||||
let picked: string[] = multi ? asList<string>(cellValue(row, col)) : [String(cellValue(row, col) ?? "")].filter(Boolean);
|
||||
let picked: string[] = multi
|
||||
? asList<string>(cellValue(row, col))
|
||||
: [String(cellValue(row, col) ?? "")].filter(Boolean);
|
||||
let active = 0;
|
||||
const chosen = h("div", { class: "dw-db-tags dw-db-pop__chosen" });
|
||||
const input = h("input", { class: "dw-db-input", placeholder: l.searchOptions, "aria-label": l.searchOptions });
|
||||
@@ -418,7 +452,11 @@ function choicePanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Column,
|
||||
h("span", { class: "dw-db-pop__check" }, picked.includes(it.o.id) ? icon("check", 13) : null),
|
||||
tag(it.o.name, it.o.color),
|
||||
);
|
||||
const more = h("button", { type: "button", class: "dw-db__btn dw-db__btn--icon dw-db-pop__more", "aria-label": l.optionColor }, icon("more", 14));
|
||||
const more = h(
|
||||
"button",
|
||||
{ type: "button", class: "dw-db__btn dw-db__btn--icon dw-db-pop__more", "aria-label": l.optionColor },
|
||||
icon("more", 14),
|
||||
);
|
||||
more.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
editOption(more, it.o);
|
||||
@@ -426,7 +464,10 @@ function choicePanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Column,
|
||||
rowEl.append(more);
|
||||
rowEl.addEventListener("click", () => toggle(it.o.id));
|
||||
} else {
|
||||
rowEl.append(h("span", { class: "dw-db-pop__check" }, icon("plus", 13)), h("span", {}, fill(l.createOption, it.name)));
|
||||
rowEl.append(
|
||||
h("span", { class: "dw-db-pop__check" }, icon("plus", 13)),
|
||||
h("span", {}, fill(l.createOption, it.name)),
|
||||
);
|
||||
rowEl.addEventListener("click", () => create(it.name));
|
||||
}
|
||||
return rowEl;
|
||||
@@ -542,7 +583,11 @@ function attachmentPanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Col
|
||||
list.replaceChildren(
|
||||
...files.map((f, i) => {
|
||||
const href = ctx.files ? ctx.files.resolve(f.src) : f.src;
|
||||
const rm = h("button", { type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": l.remove, title: l.remove }, icon("trash", 14));
|
||||
const rm = h(
|
||||
"button",
|
||||
{ type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": l.remove, title: l.remove },
|
||||
icon("trash", 14),
|
||||
);
|
||||
rm.addEventListener("click", () => {
|
||||
files = files.filter((_, j) => j !== i);
|
||||
store.setCell(row.id, col.id, files);
|
||||
@@ -551,7 +596,12 @@ function attachmentPanel(ctx: DbContext, box: HTMLDivElement, row: Row, col: Col
|
||||
return h(
|
||||
"div",
|
||||
{ class: "dw-db-pop__item" },
|
||||
h("a", { class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" }, icon("paperclip", 12), f.name),
|
||||
h(
|
||||
"a",
|
||||
{ class: "dw-db-file", href, target: "_blank", rel: "noopener noreferrer" },
|
||||
icon("paperclip", 12),
|
||||
f.name,
|
||||
),
|
||||
rm,
|
||||
);
|
||||
}),
|
||||
|
||||
@@ -5,7 +5,11 @@ import * as Y from "yjs";
|
||||
import { formatDelimited, fromCSV, parseDelimited, toCSV } from "./csv";
|
||||
import {
|
||||
convertValue,
|
||||
addDays,
|
||||
coverImage,
|
||||
daysBetween,
|
||||
timelineSpan,
|
||||
timelineStart,
|
||||
defaultView,
|
||||
groupRows,
|
||||
monthGrid,
|
||||
@@ -188,3 +192,45 @@ describe("list and gallery views", () => {
|
||||
expect(coverImage("nope")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("timeline view", () => {
|
||||
const start: Column = { id: "a", name: "Start", type: "date" };
|
||||
const end: Column = { id: "b", name: "End", type: "date" };
|
||||
|
||||
it("starts on the first date property and ends on the second", () => {
|
||||
const v = defaultView("timeline", "T", [title, start, end]);
|
||||
expect([v.dateColumn, v.endColumn, v.scale]).toEqual(["a", "b", "week"]);
|
||||
expect(
|
||||
normalize({ columns: [title, start], views: [{ id: "t", type: "timeline", dateColumn: "a", scale: "year" }] })
|
||||
.views[0]!.scale,
|
||||
).toBe("week");
|
||||
});
|
||||
|
||||
it("counts days across months and years", () => {
|
||||
expect(daysBetween("2026-12-30", "2027-01-02")).toBe(3);
|
||||
expect(addDays("2026-02-27", 2)).toBe("2026-03-01");
|
||||
expect(addDays("2026-03-01", -1)).toBe("2026-02-28");
|
||||
});
|
||||
|
||||
it("spans a record from its start to its end, or one day", () => {
|
||||
expect(timelineSpan(row("x", { a: "2026-11-10", b: "2026-11-12" }), start, end)).toEqual({
|
||||
from: "2026-11-10",
|
||||
to: "2026-11-12",
|
||||
});
|
||||
expect(timelineSpan(row("x", { a: "2026-11-10", b: "2026-11-01" }), start, end)).toEqual({
|
||||
from: "2026-11-10",
|
||||
to: "2026-11-10",
|
||||
});
|
||||
expect(timelineSpan(row("x", { a: "2026-11-10" }), start, undefined)).toEqual({
|
||||
from: "2026-11-10",
|
||||
to: "2026-11-10",
|
||||
});
|
||||
expect(timelineSpan(row("x", { b: "2026-11-10" }), start, end)).toBeNull();
|
||||
});
|
||||
|
||||
it("opens on a Monday before today", () => {
|
||||
const from = timelineStart("2026-11-19", "week"); // a Thursday
|
||||
expect(new Date(`${from}T12:00:00Z`).getUTCDay()).toBe(1);
|
||||
expect(from < "2026-11-19").toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -124,7 +124,14 @@ export function closePopover() {
|
||||
/** A text input that commits on Enter or blur and cancels on Escape. */
|
||||
export function textInput(
|
||||
value: string,
|
||||
opts: { placeholder?: string; label?: string; class?: string; type?: string; onCommit: (v: string) => void; onCancel?: () => void },
|
||||
opts: {
|
||||
placeholder?: string;
|
||||
label?: string;
|
||||
class?: string;
|
||||
type?: string;
|
||||
onCommit: (v: string) => void;
|
||||
onCancel?: () => void;
|
||||
},
|
||||
): HTMLInputElement {
|
||||
const input = h("input", {
|
||||
type: opts.type ?? "text",
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
import { Editor, mergeAttributes, Node, type AnyExtension, type JSONContent } from "@tiptap/core";
|
||||
import { Fragment, Slice, type Node as PMNode } from "@tiptap/pm/model";
|
||||
import { NodeSelection, Plugin, PluginKey } from "@tiptap/pm/state";
|
||||
import { prosemirrorJSONToYXmlFragment, ySyncPluginKey, yUndoPluginKey, yXmlFragmentToProsemirrorJSON } from "@tiptap/y-tiptap";
|
||||
import {
|
||||
prosemirrorJSONToYXmlFragment,
|
||||
ySyncPluginKey,
|
||||
yUndoPluginKey,
|
||||
yXmlFragmentToProsemirrorJSON,
|
||||
} from "@tiptap/y-tiptap";
|
||||
import * as Y from "yjs";
|
||||
import type { FileHost } from "../files";
|
||||
import { englishLabels, type EditorLabels } from "../labels";
|
||||
@@ -19,7 +24,17 @@ import type { CollabProvider } from "../provider";
|
||||
import { computeLinked, relationIds, type DatabaseChoice, type RelationTarget } from "./linked";
|
||||
import type { LinkedHost } from "./relationui";
|
||||
import { h } from "./dom";
|
||||
import { cellText, defaultView, newId, normalize, titleColumn, type Column, type DbData, type Person, type Row } from "./model";
|
||||
import {
|
||||
cellText,
|
||||
defaultView,
|
||||
newId,
|
||||
normalize,
|
||||
titleColumn,
|
||||
type Column,
|
||||
type DbData,
|
||||
type Person,
|
||||
type Row,
|
||||
} from "./model";
|
||||
import { RowPeek } from "./peek";
|
||||
import { blocksOf, DbStore, emptyDb, exportDb, readDb, seedDb } from "./store";
|
||||
import { DatabaseView } from "./view";
|
||||
@@ -271,7 +286,8 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
if (!live) return n.type.create({ ...n.attrs, id });
|
||||
const source = n.attrs.data ? normalize(n.attrs.data) : null;
|
||||
const m = blocksOf(live).get(String(n.attrs.id));
|
||||
const data = source ?? (m instanceof Y.Map ? exportDb(m, bodyJSON) : emptyDb(dbDefaults(this.options.labels)));
|
||||
const data =
|
||||
source ?? (m instanceof Y.Map ? exportDb(m, bodyJSON) : emptyDb(dbDefaults(this.options.labels)));
|
||||
seedDb(live, id, freshIds(data), (json, f) => writeBody(editor, json, f));
|
||||
return n.type.create({ id, data: null });
|
||||
});
|
||||
@@ -281,7 +297,12 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
// Two nodes never share one map: a duplicated block gets a copy of the records.
|
||||
appendTransaction: (trs, _old, state) => {
|
||||
if (!live || !trs.some((tr) => tr.docChanged && !tr.getMeta(ySyncPluginKey))) return null;
|
||||
if (!trs.some((tr) => tr.steps.some((s) => hasDatabase((s as unknown as { slice?: Slice }).slice?.content ?? Fragment.empty)))) return null;
|
||||
if (
|
||||
!trs.some((tr) =>
|
||||
tr.steps.some((s) => hasDatabase((s as unknown as { slice?: Slice }).slice?.content ?? Fragment.empty)),
|
||||
)
|
||||
)
|
||||
return null;
|
||||
const seen = new Set<string>();
|
||||
const fix: { pos: number; node: PMNode }[] = [];
|
||||
state.doc.descendants((n, pos) => {
|
||||
@@ -296,7 +317,8 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
for (const { pos, node } of fix) {
|
||||
const m = blocksOf(live).get(String(node.attrs.id));
|
||||
const id = newId();
|
||||
if (m instanceof Y.Map) seedDb(live, id, freshIds(exportDb(m, bodyJSON)), (json, f) => writeBody(editor, json, f));
|
||||
if (m instanceof Y.Map)
|
||||
seedDb(live, id, freshIds(exportDb(m, bodyJSON)), (json, f) => writeBody(editor, json, f));
|
||||
tr.setNodeMarkup(pos, undefined, { ...node.attrs, id, data: null });
|
||||
}
|
||||
return tr;
|
||||
@@ -379,7 +401,11 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
return m instanceof Y.Map ? readDb(m) : null;
|
||||
};
|
||||
/** Database ids in a page's text, in order, with their titles. */
|
||||
const databasesIn = (fragment: Y.XmlFragment, page: string, read: (id: string) => DbData | null): DatabaseChoice[] => {
|
||||
const databasesIn = (
|
||||
fragment: Y.XmlFragment,
|
||||
page: string,
|
||||
read: (id: string) => DbData | null,
|
||||
): DatabaseChoice[] => {
|
||||
const out: DatabaseChoice[] = [];
|
||||
const walk = (el: Y.XmlFragment | Y.XmlElement) => {
|
||||
for (const c of el.toArray()) {
|
||||
@@ -411,7 +437,10 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
return out;
|
||||
},
|
||||
searchPages: opts.pages
|
||||
? (q) => opts.pages!.search(q).then((list) => list.filter((p) => !isSelf(p.id)).map((p) => ({ id: p.id, title: p.title })))
|
||||
? (q) =>
|
||||
opts
|
||||
.pages!.search(q)
|
||||
.then((list) => list.filter((p) => !isSelf(p.id)).map((p) => ({ id: p.id, title: p.title })))
|
||||
: undefined,
|
||||
databasesOn: opts.linkedPages
|
||||
? (page) =>
|
||||
@@ -516,10 +545,13 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
element: el,
|
||||
editable,
|
||||
extensions: make(fragment),
|
||||
content: fragment ? undefined : { type: "doc", content: (row.body as JSONContent[] | undefined) ?? [{ type: "paragraph" }] },
|
||||
content: fragment
|
||||
? undefined
|
||||
: { type: "doc", content: (row.body as JSONContent[] | undefined) ?? [{ type: "paragraph" }] },
|
||||
editorProps: { attributes: { class: "dw-prose dw-db-peek__prose" } },
|
||||
});
|
||||
if (!fragment && !row.body?.length) el.replaceChildren(h("p", { class: "dw-db-peek__note" }, labels.database.bodyReadOnly));
|
||||
if (!fragment && !row.body?.length)
|
||||
el.replaceChildren(h("p", { class: "dw-db-peek__note" }, labels.database.bodyReadOnly));
|
||||
return () => ed.destroy();
|
||||
};
|
||||
|
||||
@@ -591,7 +623,11 @@ export const Database = Node.create<DatabaseOptions>({
|
||||
queueMicrotask(() => {
|
||||
const pos = typeof getPos === "function" ? getPos() : undefined;
|
||||
if (pos !== undefined && editor.state.doc.nodeAt(pos)?.type.name === "database") {
|
||||
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, id: key, data: null }).setMeta("addToHistory", false));
|
||||
editor.view.dispatch(
|
||||
editor.state.tr
|
||||
.setNodeMarkup(pos, undefined, { ...node.attrs, id: key, data: null })
|
||||
.setMeta("addToHistory", false),
|
||||
);
|
||||
}
|
||||
});
|
||||
m = blocksOf(doc).get(key) as Y.Map<unknown>;
|
||||
@@ -713,7 +749,10 @@ interface ListFound {
|
||||
* The list around the selection (or the top-level blocks it spans) as items:
|
||||
* each item's first line is its title, the rest its body.
|
||||
*/
|
||||
function listAt($from: import("@tiptap/pm/model").ResolvedPos, $to: import("@tiptap/pm/model").ResolvedPos): ListFound | null {
|
||||
function listAt(
|
||||
$from: import("@tiptap/pm/model").ResolvedPos,
|
||||
$to: import("@tiptap/pm/model").ResolvedPos,
|
||||
): ListFound | null {
|
||||
for (let d = $from.depth; d > 0; d--) {
|
||||
const n = $from.node(d);
|
||||
if (["bulletList", "orderedList", "taskList"].includes(n.type.name)) {
|
||||
|
||||
@@ -27,6 +27,16 @@ export const englishDatabaseLabels = {
|
||||
viewCalendar: "Calendar",
|
||||
viewList: "List",
|
||||
viewGallery: "Gallery",
|
||||
viewTimeline: "Timeline",
|
||||
endColumn: "End date property",
|
||||
sameDay: "Same day as the start",
|
||||
scaleDay: "Days",
|
||||
scaleWeek: "Weeks",
|
||||
scaleMonth: "Months",
|
||||
earlier: "Earlier",
|
||||
later: "Later",
|
||||
noStartColumn: "Add a date property to place records on the timeline.",
|
||||
dragEnd: "Drag to change the end date",
|
||||
cover: "Card cover",
|
||||
noCover: "No cover",
|
||||
noValue: "No value",
|
||||
@@ -227,6 +237,7 @@ const viewKeys: Record<ViewType, keyof DatabaseLabels> = {
|
||||
calendar: "viewCalendar",
|
||||
list: "viewList",
|
||||
gallery: "viewGallery",
|
||||
timeline: "viewTimeline",
|
||||
};
|
||||
|
||||
export const viewLabel = (l: DatabaseLabels, t: ViewType) => l[viewKeys[t]];
|
||||
|
||||
@@ -76,7 +76,11 @@ describe("relations and rollups", () => {
|
||||
|
||||
it("sorts and filters rollups as numbers", () => {
|
||||
const db = linked(projects("sum"));
|
||||
const view = { ...db.views[0]!, sorts: [{ column: "r", desc: true }], filters: [{ column: "r", op: "gt" as const, value: 5 }] };
|
||||
const view = {
|
||||
...db.views[0]!,
|
||||
sorts: [{ column: "r", desc: true }],
|
||||
filters: [{ column: "r", op: "gt" as const, value: 5 }],
|
||||
};
|
||||
expect(viewRows(db, view).map((r) => r.id)).toEqual(["p1"]);
|
||||
const empty = { ...db.views[0]!, filters: [{ column: "rel", op: "isEmpty" as const }] };
|
||||
expect(viewRows(db, empty).map((r) => r.id)).toEqual(["p2"]);
|
||||
@@ -112,7 +116,8 @@ describe("two-way relations", () => {
|
||||
{ id: "p2", cells: { t: "Docs", rel: ["k2"] } },
|
||||
],
|
||||
});
|
||||
const read = (found: DbData | null) => computeLinked(twoWay, (t) => (t.database === "projects" ? found : null), englishDatabaseLabels);
|
||||
const read = (found: DbData | null) =>
|
||||
computeLinked(twoWay, (t) => (t.database === "projects" ? found : null), englishDatabaseLabels);
|
||||
|
||||
it("keeps the mirrored column when read", () => {
|
||||
expect(twoWay.columns[1]!.relation).toEqual({ page: "", database: "projects", back: "rel" });
|
||||
|
||||
@@ -130,7 +130,9 @@ export function rollup(fn: RollupFn, related: Row[], col: Column | null, l: Pick
|
||||
case "countNotEmpty":
|
||||
return num(filled.length);
|
||||
case "percentNotEmpty":
|
||||
return related.length ? { text: `${fmt((filled.length / related.length) * 100)}%`, value: (filled.length / related.length) * 100 } : num(null);
|
||||
return related.length
|
||||
? { text: `${fmt((filled.length / related.length) * 100)}%`, value: (filled.length / related.length) * 100 }
|
||||
: num(null);
|
||||
case "sum":
|
||||
return num(nums.length ? nums.reduce((a, b) => a + b, 0) : null);
|
||||
case "average":
|
||||
@@ -160,7 +162,10 @@ export function rollup(fn: RollupFn, related: Row[], col: Column | null, l: Pick
|
||||
return num(values.filter((v) => v === true).length);
|
||||
case "percentChecked":
|
||||
return related.length
|
||||
? { text: `${fmt((values.filter((v) => v === true).length / related.length) * 100)}%`, value: (values.filter((v) => v === true).length / related.length) * 100 }
|
||||
? {
|
||||
text: `${fmt((values.filter((v) => v === true).length / related.length) * 100)}%`,
|
||||
value: (values.filter((v) => v === true).length / related.length) * 100,
|
||||
}
|
||||
: num(null);
|
||||
case "showOriginal": {
|
||||
const shown = texts.filter(Boolean);
|
||||
@@ -214,7 +219,9 @@ export function computeLinked(
|
||||
const row = byId.get(id);
|
||||
return row ? [row] : [];
|
||||
});
|
||||
const prop = cfg.property ? (target.columns.find((x) => x.id === cfg.property) ?? null) : (target.columns.find((x) => x.type === "title") ?? null);
|
||||
const prop = cfg.property
|
||||
? (target.columns.find((x) => x.id === cfg.property) ?? null)
|
||||
: (target.columns.find((x) => x.type === "title") ?? null);
|
||||
computed[c.id] = rollup(cfg.fn, related, prop, l);
|
||||
}
|
||||
return { ...r, computed };
|
||||
|
||||
@@ -75,9 +75,12 @@ export interface Row {
|
||||
}
|
||||
|
||||
/** View layouts. Clients that do not know a layout show it as a table (normalize). */
|
||||
export const viewTypes = ["table", "kanban", "calendar", "list", "gallery"] as const;
|
||||
export const viewTypes = ["table", "kanban", "calendar", "list", "gallery", "timeline"] as const;
|
||||
export type ViewType = (typeof viewTypes)[number];
|
||||
|
||||
export const timelineScales = ["day", "week", "month"] as const;
|
||||
export type TimelineScale = (typeof timelineScales)[number];
|
||||
|
||||
export type FilterOp =
|
||||
| "contains"
|
||||
| "notContains"
|
||||
@@ -121,6 +124,10 @@ export interface View {
|
||||
dateColumn: string | null;
|
||||
/** The attachment column whose first image is a gallery card's cover; null for none. */
|
||||
cover: string | null;
|
||||
/** The date column a timeline bar ends on (inclusive); null: bars last one day. dateColumn is the start. */
|
||||
endColumn: string | null;
|
||||
/** How much time a timeline shows: days, weeks or months. */
|
||||
scale: TimelineScale;
|
||||
/** Column widths in pixels, by column id. */
|
||||
widths: Record<string, number>;
|
||||
}
|
||||
@@ -145,6 +152,7 @@ export function newId(): string {
|
||||
export function defaultView(type: ViewType, name: string, columns: Column[]): View {
|
||||
const groupable = columns.find((c) => groupableTypes.includes(c.type));
|
||||
const date = columns.find((c) => c.type === "date" || c.type === "createdTime");
|
||||
const dates = columns.filter((c) => c.type === "date");
|
||||
return {
|
||||
id: newId(),
|
||||
name,
|
||||
@@ -154,8 +162,10 @@ export function defaultView(type: ViewType, name: string, columns: Column[]): Vi
|
||||
filterMode: "and",
|
||||
sorts: [],
|
||||
groupBy: type === "kanban" ? (groupable?.id ?? null) : null,
|
||||
dateColumn: type === "calendar" ? (date?.id ?? null) : null,
|
||||
dateColumn: type === "calendar" || type === "timeline" ? (date?.id ?? null) : null,
|
||||
cover: type === "gallery" ? (columns.find((c) => c.type === "attachment")?.id ?? null) : null,
|
||||
endColumn: type === "timeline" ? (dates.find((c) => c.id !== date?.id)?.id ?? null) : null,
|
||||
scale: "week",
|
||||
widths: {},
|
||||
};
|
||||
}
|
||||
@@ -216,6 +226,8 @@ export function normalize(raw: unknown): DbData {
|
||||
groupBy: typeof v.groupBy === "string" && ids.has(v.groupBy) ? v.groupBy : null,
|
||||
dateColumn: typeof v.dateColumn === "string" && ids.has(v.dateColumn) ? v.dateColumn : null,
|
||||
cover: typeof v.cover === "string" && ids.has(v.cover) ? v.cover : null,
|
||||
endColumn: typeof v.endColumn === "string" && ids.has(v.endColumn) ? v.endColumn : null,
|
||||
scale: (timelineScales as readonly string[]).includes(String(v.scale)) ? (v.scale as TimelineScale) : "week",
|
||||
widths: isObject(v.widths)
|
||||
? Object.fromEntries(Object.entries(v.widths).filter((e): e is [string, number] => typeof e[1] === "number"))
|
||||
: {},
|
||||
@@ -660,3 +672,45 @@ export function coverImage(v: unknown): string {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/** Days between two ISO dates (b - a). */
|
||||
export function daysBetween(a: string, b: string): number {
|
||||
return Math.round(
|
||||
(Date.UTC(+b.slice(0, 4), +b.slice(5, 7) - 1, +b.slice(8, 10)) -
|
||||
Date.UTC(+a.slice(0, 4), +a.slice(5, 7) - 1, +a.slice(8, 10))) /
|
||||
86_400_000,
|
||||
);
|
||||
}
|
||||
|
||||
/** The ISO date n days after day. */
|
||||
export function addDays(day: string, n: number): string {
|
||||
const d = new Date(Date.UTC(+day.slice(0, 4), +day.slice(5, 7) - 1, +day.slice(8, 10) + n));
|
||||
return d.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a record sits on a timeline: its first and last day (inclusive), or
|
||||
* null without a start. A missing or earlier end is the start day.
|
||||
*/
|
||||
export function timelineSpan(row: Row, start: Column, end: Column | undefined): { from: string; to: string } | null {
|
||||
const from = dateOf(cellValue(row, start));
|
||||
if (!from) return null;
|
||||
const last = end ? dateOf(cellValue(row, end)) : "";
|
||||
return { from, to: last && last >= from ? last : from };
|
||||
}
|
||||
|
||||
/** Pixels per day, and how many days a timeline shows, at each scale. */
|
||||
export const timelineScale: Record<TimelineScale, { px: number; days: number; step: number }> = {
|
||||
day: { px: 44, days: 28, step: 7 },
|
||||
week: { px: 20, days: 70, step: 28 },
|
||||
month: { px: 6, days: 240, step: 90 },
|
||||
};
|
||||
|
||||
/** The first day a timeline at this scale shows to have today in view. */
|
||||
export function timelineStart(today: string, scale: TimelineScale): string {
|
||||
const back = scale === "day" ? 3 : scale === "week" ? 14 : 30;
|
||||
const d = addDays(today, -back);
|
||||
// Weeks start on Monday, so day and week columns line up with the calendar.
|
||||
const dow = (new Date(`${d}T12:00:00Z`).getUTCDay() + 6) % 7;
|
||||
return addDays(d, -dow);
|
||||
}
|
||||
@@ -28,7 +28,9 @@ it("follows its map when the server replaces it (a restore or import)", () => {
|
||||
document.body.append(el);
|
||||
editor = new Editor({
|
||||
element: el,
|
||||
extensions: docwellExtensions({ collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } } }),
|
||||
extensions: docwellExtensions({
|
||||
collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } },
|
||||
}),
|
||||
});
|
||||
editor.commands.insertDatabase(db(["one", "two"]));
|
||||
expect(titles(el)).toEqual(["one", "two"]);
|
||||
|
||||
@@ -6,15 +6,7 @@ import type { DbContext } from "./cells";
|
||||
import { typeIcons } from "./cells";
|
||||
import { h, icon } from "./dom";
|
||||
import { opLabel, typeLabel } from "./labels";
|
||||
import {
|
||||
filterOps,
|
||||
groupableTypes,
|
||||
opTakesValue,
|
||||
type Column,
|
||||
type Filter,
|
||||
type FilterOp,
|
||||
type View,
|
||||
} from "./model";
|
||||
import { filterOps, groupableTypes, opTakesValue, type Column, type Filter, type FilterOp, type View } from "./model";
|
||||
|
||||
function select<T extends string>(
|
||||
value: T | "",
|
||||
@@ -47,11 +39,23 @@ function filterValue(ctx: DbContext, col: Column, f: Filter, set: (v: unknown) =
|
||||
set,
|
||||
);
|
||||
}
|
||||
const type = col.type === "date" || col.type === "createdTime" ? "date" : col.type === "number" || col.type === "progress" ? "number" : "text";
|
||||
const input = h("input", { class: "dw-db-input dw-db-input--small", type, "aria-label": l.value, placeholder: l.value });
|
||||
const type =
|
||||
col.type === "date" || col.type === "createdTime"
|
||||
? "date"
|
||||
: col.type === "number" || col.type === "progress"
|
||||
? "number"
|
||||
: "text";
|
||||
const input = h("input", {
|
||||
class: "dw-db-input dw-db-input--small",
|
||||
type,
|
||||
"aria-label": l.value,
|
||||
placeholder: l.value,
|
||||
});
|
||||
input.value = f.value === undefined || f.value === null ? "" : String(f.value);
|
||||
input.addEventListener("keydown", (e) => e.stopPropagation());
|
||||
input.addEventListener("change", () => set(type === "number" ? (input.value === "" ? null : Number(input.value)) : input.value));
|
||||
input.addEventListener("change", () =>
|
||||
set(type === "number" ? (input.value === "" ? null : Number(input.value)) : input.value),
|
||||
);
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -65,13 +69,18 @@ export function filterPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
box.replaceChildren();
|
||||
if (filters.length > 1) {
|
||||
box.append(
|
||||
select(view.filterMode, [
|
||||
{ value: "and", label: l.matchAll },
|
||||
{ value: "or", label: l.matchAny },
|
||||
], l.filter, (v) => {
|
||||
view.filterMode = v as "and" | "or";
|
||||
store?.updateView(view.id, { filterMode: view.filterMode });
|
||||
}),
|
||||
select(
|
||||
view.filterMode,
|
||||
[
|
||||
{ value: "and", label: l.matchAll },
|
||||
{ value: "or", label: l.matchAny },
|
||||
],
|
||||
l.filter,
|
||||
(v) => {
|
||||
view.filterMode = v as "and" | "or";
|
||||
store?.updateView(view.id, { filterMode: view.filterMode });
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!filters.length) box.append(h("p", { class: "dw-db-pop__empty" }, l.noFilters));
|
||||
@@ -88,12 +97,17 @@ export function filterPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
save();
|
||||
draw();
|
||||
}),
|
||||
select<FilterOp>(f.op, ops.map((op) => ({ value: op, label: opLabel(l, op) })), l.filter, (op) => {
|
||||
filters[i] = { ...f, op };
|
||||
if (!opTakesValue(op)) delete filters[i]!.value;
|
||||
save();
|
||||
draw();
|
||||
}),
|
||||
select<FilterOp>(
|
||||
f.op,
|
||||
ops.map((op) => ({ value: op, label: opLabel(l, op) })),
|
||||
l.filter,
|
||||
(op) => {
|
||||
filters[i] = { ...f, op };
|
||||
if (!opTakesValue(op)) delete filters[i]!.value;
|
||||
save();
|
||||
draw();
|
||||
},
|
||||
),
|
||||
filterValue(ctx, col, f, (v) => {
|
||||
filters[i] = { ...filters[i]!, value: v };
|
||||
save();
|
||||
@@ -138,13 +152,18 @@ export function sortPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
sorts[i] = { ...s, column: id };
|
||||
save();
|
||||
}),
|
||||
select(s.desc ? "desc" : "asc", [
|
||||
{ value: "asc", label: l.ascending },
|
||||
{ value: "desc", label: l.descending },
|
||||
], l.sort, (v) => {
|
||||
sorts[i] = { ...s, desc: v === "desc" };
|
||||
save();
|
||||
}),
|
||||
select(
|
||||
s.desc ? "desc" : "asc",
|
||||
[
|
||||
{ value: "asc", label: l.ascending },
|
||||
{ value: "desc", label: l.descending },
|
||||
],
|
||||
l.sort,
|
||||
(v) => {
|
||||
sorts[i] = { ...s, desc: v === "desc" };
|
||||
save();
|
||||
},
|
||||
),
|
||||
removeButton(l.remove, () => {
|
||||
sorts.splice(i, 1);
|
||||
save();
|
||||
@@ -200,6 +219,22 @@ export function datePanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
);
|
||||
}
|
||||
|
||||
/** The property a timeline's bars end on; without one, bars last a day. */
|
||||
export function endPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
const store = ctx.store;
|
||||
const l = ctx.labels;
|
||||
const dates = ctx.db.columns.filter((c) => c.type === "date" && c.id !== view.dateColumn);
|
||||
box.append(
|
||||
h("label", { class: "dw-db-pop__label" }, l.endColumn),
|
||||
select(
|
||||
view.endColumn ?? "",
|
||||
[{ value: "", label: l.sameDay }, ...dates.map((c) => ({ value: c.id, label: c.name || typeLabel(l, c.type) }))],
|
||||
l.endColumn,
|
||||
(v) => store?.updateView(view.id, { endColumn: v || null }),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** The attachment property whose first image covers a gallery's cards. */
|
||||
export function coverPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
const store = ctx.store;
|
||||
@@ -216,12 +251,14 @@ export function coverPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Which properties the view shows. */
|
||||
export function propertiesPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
/** Which properties the view shows. It draws into a box of its own, below any settings put in before it. */
|
||||
export function propertiesPanel(ctx: DbContext, outer: HTMLElement, view: View) {
|
||||
const store = ctx.store;
|
||||
const l = ctx.labels;
|
||||
let hidden = [...view.hidden];
|
||||
const save = () => store?.updateView(view.id, { hidden });
|
||||
const box = h("div", { class: "dw-db-pop__props" });
|
||||
outer.append(box);
|
||||
const draw = () => {
|
||||
box.replaceChildren();
|
||||
const others = ctx.db.columns.filter((c) => c.type !== "title");
|
||||
@@ -261,7 +298,11 @@ export function propertiesPanel(ctx: DbContext, box: HTMLElement, view: View) {
|
||||
}
|
||||
|
||||
function removeButton(label: string, onClick: () => void) {
|
||||
const b = h("button", { type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": label, title: label }, icon("close", 14));
|
||||
const b = h(
|
||||
"button",
|
||||
{ type: "button", class: "dw-db__btn dw-db__btn--icon", "aria-label": label, title: label },
|
||||
icon("close", 14),
|
||||
);
|
||||
b.addEventListener("click", onClick);
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,13 @@ export class RowPeek {
|
||||
private onClose: () => void,
|
||||
) {
|
||||
this.returnFocus = document.activeElement;
|
||||
this.panel = h("div", { class: "dw-db-peek__panel", role: "dialog", "aria-modal": "true", tabIndex: -1 }, this.head, this.props, this.bodyEl);
|
||||
this.panel = h(
|
||||
"div",
|
||||
{ class: "dw-db-peek__panel", role: "dialog", "aria-modal": "true", tabIndex: -1 },
|
||||
this.head,
|
||||
this.props,
|
||||
this.bodyEl,
|
||||
);
|
||||
this.dom = h("div", { class: host.page ? "dw-db-peek dw-db-peek--page" : "dw-db-peek" }, this.panel);
|
||||
this.dom.addEventListener("mousedown", (e) => {
|
||||
if (e.target === this.dom && !this.host.page) this.close();
|
||||
@@ -135,7 +141,11 @@ export class RowPeek {
|
||||
const titleText = String(cellValue(row, title) ?? "");
|
||||
const titleEl = store
|
||||
? (() => {
|
||||
const input = h("input", { class: "dw-db-peek__title", placeholder: l.untitledRow, "aria-label": title.name || l.typeTitle });
|
||||
const input = h("input", {
|
||||
class: "dw-db-peek__title",
|
||||
placeholder: l.untitledRow,
|
||||
"aria-label": title.name || l.typeTitle,
|
||||
});
|
||||
input.value = titleText;
|
||||
input.addEventListener("focus", () => ctx.setEditing(true));
|
||||
input.addEventListener("blur", () => {
|
||||
@@ -154,7 +164,14 @@ export class RowPeek {
|
||||
const lines = this.db.columns
|
||||
.filter((c) => c.type !== "title")
|
||||
.map((c) => {
|
||||
const value = h("div", { class: `dw-db-peek__value dw-db-t__cell--${c.type}`, tabIndex: store && !readOnlyTypes.includes(c.type) ? 0 : -1 }, renderCell(ctx, row, c));
|
||||
const value = h(
|
||||
"div",
|
||||
{
|
||||
class: `dw-db-peek__value dw-db-t__cell--${c.type}`,
|
||||
tabIndex: store && !readOnlyTypes.includes(c.type) ? 0 : -1,
|
||||
},
|
||||
renderCell(ctx, row, c),
|
||||
);
|
||||
const edit = () => {
|
||||
if (!store) return;
|
||||
editCell(ctx, value, row, c, { onDone: () => this.draw(false) });
|
||||
@@ -172,19 +189,33 @@ export class RowPeek {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "dw-db-peek__prop" },
|
||||
h("div", { class: "dw-db-peek__label" }, icon(typeIcons[c.type], 14), h("span", {}, c.name || typeLabel(l, c.type))),
|
||||
h(
|
||||
"div",
|
||||
{ class: "dw-db-peek__label" },
|
||||
icon(typeIcons[c.type], 14),
|
||||
h("span", {}, c.name || typeLabel(l, c.type)),
|
||||
),
|
||||
value,
|
||||
);
|
||||
});
|
||||
const children: Node[] = [titleEl, ...lines];
|
||||
if (store) {
|
||||
const add = iconButton("plus", l.addColumn, () =>
|
||||
openBlockMenu(
|
||||
add,
|
||||
editableTypes.map((t) => ({ id: t, label: typeLabel(l, t), icon: typeIcons[t], run: () => store.addColumn(t, typeLabel(l, t)) })),
|
||||
l.addColumn,
|
||||
),
|
||||
l.addColumn);
|
||||
const add = iconButton(
|
||||
"plus",
|
||||
l.addColumn,
|
||||
() =>
|
||||
openBlockMenu(
|
||||
add,
|
||||
editableTypes.map((t) => ({
|
||||
id: t,
|
||||
label: typeLabel(l, t),
|
||||
icon: typeIcons[t],
|
||||
run: () => store.addColumn(t, typeLabel(l, t)),
|
||||
})),
|
||||
l.addColumn,
|
||||
),
|
||||
l.addColumn,
|
||||
);
|
||||
add.classList.add("dw-db-peek__add");
|
||||
children.push(add);
|
||||
}
|
||||
@@ -206,6 +237,7 @@ export class RowPeek {
|
||||
this.dom.remove();
|
||||
this.onClose();
|
||||
if (leave) this.host.page?.onLeave?.();
|
||||
if (this.returnFocus instanceof HTMLElement && this.returnFocus.isConnected) this.returnFocus.focus({ preventScroll: true });
|
||||
if (this.returnFocus instanceof HTMLElement && this.returnFocus.isConnected)
|
||||
this.returnFocus.focus({ preventScroll: true });
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,14 @@
|
||||
import type { DbContext } from "./cells";
|
||||
import { h, icon, popover } from "./dom";
|
||||
import { fill, typeLabel, type DatabaseLabels } from "./labels";
|
||||
import { linkedIds, rollupFnsFor, type DatabaseChoice, type RelationTarget, type RollupConfig, type RollupFn } from "./linked";
|
||||
import {
|
||||
linkedIds,
|
||||
rollupFnsFor,
|
||||
type DatabaseChoice,
|
||||
type RelationTarget,
|
||||
type RollupConfig,
|
||||
type RollupFn,
|
||||
} from "./linked";
|
||||
import { cellText, titleColumn, type Column, type DbData, type Row } from "./model";
|
||||
|
||||
/** What relation cells and settings need from the block (index.ts fills it in). */
|
||||
@@ -35,7 +42,9 @@ export interface LinkedHost {
|
||||
function mirrorable(linked: LinkedHost, t: RelationTarget): Column[] {
|
||||
const db = linked.read(t);
|
||||
if (!db || !linked.pointsHere) return [];
|
||||
return db.columns.filter((c) => c.type === "relation" && c.relation && !c.relation.back && linked.pointsHere!(t, c.relation));
|
||||
return db.columns.filter(
|
||||
(c) => c.type === "relation" && c.relation && !c.relation.back && linked.pointsHere!(t, c.relation),
|
||||
);
|
||||
}
|
||||
|
||||
const fnKey = (fn: RollupFn) => `fn${fn[0]!.toUpperCase()}${fn.slice(1)}` as keyof DatabaseLabels;
|
||||
@@ -82,10 +91,15 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column
|
||||
close();
|
||||
}),
|
||||
...mirrors.map((m) =>
|
||||
item(fill(l.relationMirror, m.name || l.typeRelation), same && current!.back === m.id, () => {
|
||||
store.setRelation(col.id, { ...target, back: m.id });
|
||||
close();
|
||||
}, l.relationTwoWay),
|
||||
item(
|
||||
fill(l.relationMirror, m.name || l.typeRelation),
|
||||
same && current!.back === m.id,
|
||||
() => {
|
||||
store.setRelation(col.id, { ...target, back: m.id });
|
||||
close();
|
||||
},
|
||||
l.relationTwoWay,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -97,7 +111,9 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column
|
||||
h("div", { class: "dw-db-pop__heading" }, l.relationThisPage),
|
||||
...(local.length
|
||||
? local.map((c) =>
|
||||
item(c.title || l.untitled, !!current && !current.page && current.database === c.database, () => pick(c)),
|
||||
item(c.title || l.untitled, !!current && !current.page && current.database === c.database, () =>
|
||||
pick(c),
|
||||
),
|
||||
)
|
||||
: [h("div", { class: "dw-db-pop__empty" }, l.relationNoDatabases)]),
|
||||
);
|
||||
@@ -105,7 +121,11 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column
|
||||
drawLocal();
|
||||
box.append(h("div", { class: "dw-db-pop__title" }, l.relationPick), list);
|
||||
if (linked.searchPages && linked.databasesOn) {
|
||||
const input = h("input", { class: "dw-db-input", placeholder: l.relationSearchPage, "aria-label": l.relationOtherPage });
|
||||
const input = h("input", {
|
||||
class: "dw-db-input",
|
||||
placeholder: l.relationSearchPage,
|
||||
"aria-label": l.relationOtherPage,
|
||||
});
|
||||
const found = h("div", { class: "dw-db-pop__list", role: "listbox" });
|
||||
let seq = 0;
|
||||
input.addEventListener("input", async () => {
|
||||
@@ -123,7 +143,9 @@ export function relationTargetPanel(ctx: DbContext, anchor: Element, col: Column
|
||||
h("div", { class: "dw-db-pop__heading" }, p.title || l.untitled),
|
||||
...(dbs.length
|
||||
? dbs.map((c) =>
|
||||
item(c.title || l.untitled, current?.page === c.page && current.database === c.database, () => pick(c)),
|
||||
item(c.title || l.untitled, current?.page === c.page && current.database === c.database, () =>
|
||||
pick(c),
|
||||
),
|
||||
)
|
||||
: [h("div", { class: "dw-db-pop__empty" }, l.relationNoDatabases)]),
|
||||
);
|
||||
@@ -280,13 +302,18 @@ export function rollupPanel(ctx: DbContext, anchor: Element, col: Column, onDone
|
||||
const fns = rollupFnsFor(prop ? prop.type : "");
|
||||
if (!fns.includes(cfg.fn)) cfg.fn = cfg.property ? fns[0]! : "count";
|
||||
box.replaceChildren(
|
||||
select(l.rollupRelation, relations.map((c) => [c.id, c.name || l.typeRelation]), rel.id, (v) => {
|
||||
cfg.relation = v;
|
||||
cfg.property = "";
|
||||
cfg.fn = "count";
|
||||
store.setRollup(col.id, { ...cfg });
|
||||
draw();
|
||||
}),
|
||||
select(
|
||||
l.rollupRelation,
|
||||
relations.map((c) => [c.id, c.name || l.typeRelation]),
|
||||
rel.id,
|
||||
(v) => {
|
||||
cfg.relation = v;
|
||||
cfg.property = "";
|
||||
cfg.fn = "count";
|
||||
store.setRollup(col.id, { ...cfg });
|
||||
draw();
|
||||
},
|
||||
),
|
||||
select(l.rollupProperty, props, cfg.property, (v) => {
|
||||
cfg.property = v;
|
||||
const t = target?.columns.find((c) => c.id === v);
|
||||
@@ -294,10 +321,15 @@ export function rollupPanel(ctx: DbContext, anchor: Element, col: Column, onDone
|
||||
store.setRollup(col.id, { ...cfg });
|
||||
draw();
|
||||
}),
|
||||
select(l.rollupFn, (cfg.property ? fns : (["count", "showOriginal"] as RollupFn[])).map((f) => [f, rollupFnLabel(l, f)]), cfg.fn, (v) => {
|
||||
cfg.fn = v as RollupFn;
|
||||
store.setRollup(col.id, { ...cfg });
|
||||
}),
|
||||
select(
|
||||
l.rollupFn,
|
||||
(cfg.property ? fns : (["count", "showOriginal"] as RollupFn[])).map((f) => [f, rollupFnLabel(l, f)]),
|
||||
cfg.fn,
|
||||
(v) => {
|
||||
cfg.fn = v as RollupFn;
|
||||
store.setRollup(col.id, { ...cfg });
|
||||
},
|
||||
),
|
||||
target ? h("span") : h("div", { class: "dw-db-pop__empty" }, l.relationMissing),
|
||||
);
|
||||
};
|
||||
@@ -316,7 +348,11 @@ export function renderRelation(ctx: DbContext, row: Row, col: Column): HTMLEleme
|
||||
if (c?.links && col.relation) {
|
||||
const target = col.relation;
|
||||
for (const link of c.links) {
|
||||
const a = h("button", { type: "button", class: "dw-db-tag dw-db-rel", dataset: { color: "gray" }, title: ctx.labels.openRelated }, link.title || ctx.labels.untitledRow);
|
||||
const a = h(
|
||||
"button",
|
||||
{ type: "button", class: "dw-db-tag dw-db-rel", dataset: { color: "gray" }, title: ctx.labels.openRelated },
|
||||
link.title || ctx.labels.untitledRow,
|
||||
);
|
||||
a.addEventListener("click", (e) => {
|
||||
// A click on a chip opens the record; the cell itself edits.
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -35,7 +35,7 @@ type YItem = Y.Map<unknown>;
|
||||
export function dbToY(data: DbData): YItem {
|
||||
const m = new Y.Map<unknown>();
|
||||
m.set("title", data.title);
|
||||
const list = <T,>(items: T[], toY: (x: T) => YItem) => {
|
||||
const list = <T>(items: T[], toY: (x: T) => YItem) => {
|
||||
const a = new Y.Array<YItem>();
|
||||
a.push(items.map((x, i) => withPos(toY(x), i)));
|
||||
return a;
|
||||
|
||||
@@ -66,7 +66,10 @@ export function touchDraggable(handle: HTMLElement, d: TouchDrag): void {
|
||||
const dx = x < EDGE ? -1 : x > innerWidth - EDGE ? 1 : 0;
|
||||
const dy = y < EDGE ? -1 : y > innerHeight - EDGE ? 1 : 0;
|
||||
let moved = false;
|
||||
for (const [axis, dir] of [["x", dx], ["y", dy]] as const) {
|
||||
for (const [axis, dir] of [
|
||||
["x", dx],
|
||||
["y", dy],
|
||||
] as const) {
|
||||
if (!dir) continue;
|
||||
const s = scroller(d.source, axis) ?? (axis === "y" ? document.scrollingElement : null);
|
||||
if (!s) continue;
|
||||
|
||||
@@ -44,7 +44,9 @@ const projects: DbData = {
|
||||
|
||||
/** What a column's cells show, row by row. */
|
||||
const readRelationCell = (node: HTMLElement, col: string) =>
|
||||
[...node.querySelectorAll<HTMLElement>(`tbody tr[data-row] td[data-col="${col}"]`)].map((td) => td.textContent?.trim() ?? "");
|
||||
[...node.querySelectorAll<HTMLElement>(`tbody tr[data-row] td[data-col="${col}"]`)].map(
|
||||
(td) => td.textContent?.trim() ?? "",
|
||||
);
|
||||
const nodes = () => [...document.querySelectorAll<HTMLElement>(".dw-db-node")];
|
||||
const clickText = (selector: string, text: string) => {
|
||||
const el = [...document.querySelectorAll<HTMLElement>(selector)].find((e) => e.textContent?.includes(text));
|
||||
@@ -58,7 +60,9 @@ function mount(doc: Y.Doc) {
|
||||
document.body.append(el);
|
||||
editor = new Editor({
|
||||
element: el,
|
||||
extensions: docwellExtensions({ collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } } }),
|
||||
extensions: docwellExtensions({
|
||||
collab: { provider: { doc, awareness: new Awareness(doc) } as never, user: { name: "A", color: "#888" } },
|
||||
}),
|
||||
});
|
||||
// Seeded under fixed ids, so the relation finds its database.
|
||||
editor.commands.setContent({
|
||||
@@ -80,7 +84,9 @@ it("adds the other side and keeps links in the relation that stores them", async
|
||||
expect(nodes()).toHaveLength(2);
|
||||
|
||||
// Projects → column menu → Related database → "Show on “Tasks” too".
|
||||
const head = [...nodes()[0]!.querySelectorAll<HTMLElement>(".dw-db-t__head")].find((b) => b.textContent?.includes("Tasks"))!;
|
||||
const head = [...nodes()[0]!.querySelectorAll<HTMLElement>(".dw-db-t__head")].find((b) =>
|
||||
b.textContent?.includes("Tasks"),
|
||||
)!;
|
||||
head.click();
|
||||
clickText(".dw-block-menu [role=menuitem]", "Related database");
|
||||
clickText(".dw-db-pop button", "Show on “Tasks” too");
|
||||
@@ -124,7 +130,9 @@ it("offers to mirror a relation that already links here", async () => {
|
||||
// A new property starts as a name field; its menu sets the related database.
|
||||
(document.activeElement as HTMLElement | null)?.blur();
|
||||
await flush();
|
||||
const head = [...nodes()[1]!.querySelectorAll<HTMLElement>(".dw-db-t__head")].find((x) => x.textContent?.includes("Relation"))!;
|
||||
const head = [...nodes()[1]!.querySelectorAll<HTMLElement>(".dw-db-t__head")].find((x) =>
|
||||
x.textContent?.includes("Relation"),
|
||||
)!;
|
||||
head.click();
|
||||
clickText(".dw-block-menu [role=menuitem]", "Related database");
|
||||
clickText(".dw-db-pop [role=option]", "Projects");
|
||||
|
||||
@@ -15,14 +15,20 @@ import { touchDraggable } from "./touchdrag";
|
||||
import {
|
||||
cellText,
|
||||
cellValue,
|
||||
addDays,
|
||||
coverImage,
|
||||
dateOf,
|
||||
daysBetween,
|
||||
editableTypes,
|
||||
filterOps,
|
||||
groupRows,
|
||||
isoDay,
|
||||
monthGrid,
|
||||
moveToGroup,
|
||||
timelineScale,
|
||||
timelineScales,
|
||||
timelineSpan,
|
||||
timelineStart,
|
||||
titleColumn,
|
||||
viewRows,
|
||||
viewTypes,
|
||||
@@ -31,6 +37,7 @@ import {
|
||||
type DbData,
|
||||
type Group,
|
||||
type Row,
|
||||
type TimelineScale,
|
||||
type View,
|
||||
type ViewType,
|
||||
} from "./model";
|
||||
@@ -65,6 +72,9 @@ export class DatabaseView {
|
||||
private anchor: { row: string; col: string } | null = null;
|
||||
private picked = new Set<string>();
|
||||
private month: { y: number; m: number };
|
||||
/** The first day the timeline shows ("" = around today), and a zoom kept by people who cannot edit. */
|
||||
private tlFrom = "";
|
||||
private tlScale: TimelineScale | null = null;
|
||||
|
||||
private titleEl = h("div", { class: "dw-db__title" });
|
||||
private tabs = h("div", { class: "dw-db__tabs", role: "tablist" });
|
||||
@@ -260,7 +270,7 @@ export class DatabaseView {
|
||||
count(b.sort, v.sorts.length);
|
||||
b.sort.hidden = v.type === "calendar";
|
||||
b.group.classList.toggle("is-on", !!v.groupBy && groupedLayouts.includes(v.type));
|
||||
b.group.hidden = v.type === "calendar";
|
||||
b.group.hidden = v.type === "calendar" || v.type === "timeline";
|
||||
b.add.hidden = !this.editable;
|
||||
this.drawBulk();
|
||||
}
|
||||
@@ -302,7 +312,8 @@ export class DatabaseView {
|
||||
else if (kind === "sort") p.sortPanel(ctx, box, view);
|
||||
else if (kind === "group") p.groupPanel(ctx, box, view);
|
||||
else {
|
||||
if (view.type === "calendar") p.datePanel(ctx, box, view);
|
||||
if (view.type === "calendar" || view.type === "timeline") p.datePanel(ctx, box, view);
|
||||
if (view.type === "timeline") p.endPanel(ctx, box, view);
|
||||
if (view.type === "kanban") p.groupPanel(ctx, box, view);
|
||||
if (view.type === "gallery") p.coverPanel(ctx, box, view);
|
||||
p.propertiesPanel(ctx, box, view);
|
||||
@@ -372,8 +383,13 @@ export class DatabaseView {
|
||||
if (type === "kanban" && !v.groupBy)
|
||||
patch.groupBy = cols.find((c) => ["select", "multiSelect", "checkbox", "member"].includes(c.type))?.id ?? null;
|
||||
if (type === "gallery" && !v.cover) patch.cover = cols.find((c) => c.type === "attachment")?.id ?? null;
|
||||
if (type === "calendar" && !v.dateColumn) patch.dateColumn = cols.find((c) => c.type === "date")?.id ?? null;
|
||||
if (type === "calendar" && !patch.dateColumn && !v.dateColumn && this.host.store) {
|
||||
const dated = type === "calendar" || type === "timeline";
|
||||
if (dated && !v.dateColumn) patch.dateColumn = cols.find((c) => c.type === "date")?.id ?? null;
|
||||
if (type === "timeline" && !v.endColumn) {
|
||||
const start = patch.dateColumn ?? v.dateColumn;
|
||||
patch.endColumn = cols.find((c) => c.type === "date" && c.id !== start)?.id ?? null;
|
||||
}
|
||||
if (dated && !patch.dateColumn && !v.dateColumn && this.host.store) {
|
||||
patch.dateColumn = this.host.store.addColumn("date", this.labels.typeDate);
|
||||
}
|
||||
this.host.store?.updateView(v.id, patch);
|
||||
@@ -496,6 +512,7 @@ export class DatabaseView {
|
||||
if (v.type === "kanban") this.drawKanban(v);
|
||||
else if (v.type === "calendar") this.drawCalendar(v);
|
||||
else if (v.type === "list" || v.type === "gallery") this.drawItems(v);
|
||||
else if (v.type === "timeline") this.drawTimeline(v);
|
||||
else this.drawTable(v);
|
||||
}
|
||||
|
||||
@@ -1437,6 +1454,307 @@ export class DatabaseView {
|
||||
this.body.replaceChildren(...children);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- timeline
|
||||
|
||||
/**
|
||||
* Records as bars from their start date to their end date, one row each,
|
||||
* in the view's order. Bars are dragged to move a record (both dates move)
|
||||
* and by their right edge to change its end. Records without a start are
|
||||
* listed below, like on the calendar.
|
||||
*/
|
||||
private drawTimeline(v: View) {
|
||||
const l = this.labels;
|
||||
const start = this.db.columns.find((c) => c.id === v.dateColumn);
|
||||
if (!start) {
|
||||
this.body.replaceChildren(h("p", { class: "dw-db__empty" }, l.noStartColumn));
|
||||
return;
|
||||
}
|
||||
const end = this.db.columns.find((c) => c.id === v.endColumn && c.type === "date");
|
||||
const scale = this.tlScale ?? v.scale;
|
||||
const { px, days, step } = timelineScale[scale];
|
||||
const today = isoDay(new Date());
|
||||
const from = this.tlFrom || timelineStart(today, scale);
|
||||
const last = addDays(from, days - 1);
|
||||
const movable = this.editable && start.type === "date";
|
||||
const title = titleColumn(this.db);
|
||||
const rows = viewRows(this.db, v, this.search);
|
||||
const placed: { r: Row; span: { from: string; to: string } }[] = [];
|
||||
const undated: Row[] = [];
|
||||
for (const r of rows) {
|
||||
const span = timelineSpan(r, start, end);
|
||||
if (span) placed.push({ r, span });
|
||||
else undated.push(r);
|
||||
}
|
||||
const locale = this.host.locale;
|
||||
const fmt = (day: string, o: Intl.DateTimeFormatOptions) =>
|
||||
new Date(`${day}T12:00:00Z`).toLocaleDateString(locale, { ...o, timeZone: "UTC" });
|
||||
|
||||
// Navigation and zoom.
|
||||
const go = (n: number) => {
|
||||
this.tlFrom = addDays(from, n);
|
||||
this.drawBody();
|
||||
};
|
||||
const zoom = h("div", { class: "dw-db-tl__zoom", role: "group" });
|
||||
for (const sc of timelineScales) {
|
||||
const label = sc === "day" ? l.scaleDay : sc === "week" ? l.scaleWeek : l.scaleMonth;
|
||||
const b = h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: sc === scale ? "dw-db__btn is-on" : "dw-db__btn",
|
||||
"aria-pressed": String(sc === scale),
|
||||
},
|
||||
label,
|
||||
);
|
||||
b.addEventListener("click", () => {
|
||||
this.tlFrom = "";
|
||||
if (this.editable && this.host.store) {
|
||||
this.tlScale = null;
|
||||
this.host.store.updateView(v.id, { scale: sc });
|
||||
} else {
|
||||
this.tlScale = sc;
|
||||
this.drawBody();
|
||||
}
|
||||
});
|
||||
zoom.append(b);
|
||||
}
|
||||
const nav = h(
|
||||
"div",
|
||||
{ class: "dw-db-c__nav" },
|
||||
h(
|
||||
"strong",
|
||||
{ class: "dw-db-c__month" },
|
||||
`${fmt(from, { day: "numeric", month: "short" })} – ${fmt(last, { day: "numeric", month: "short", year: "numeric" })}`,
|
||||
),
|
||||
iconButton("chevron-left", l.earlier, () => go(-step)),
|
||||
iconButton("chevron-right", l.later, () => go(step)),
|
||||
iconButton(
|
||||
"calendar",
|
||||
l.today,
|
||||
() => {
|
||||
this.tlFrom = "";
|
||||
this.drawBody();
|
||||
},
|
||||
l.today,
|
||||
),
|
||||
zoom,
|
||||
);
|
||||
|
||||
// The scale along the top: every day, every Monday, or every first of the month.
|
||||
const width = days * px;
|
||||
const ticks = h("div", { class: "dw-db-tl__ticks", style: { width: `${width}px` } });
|
||||
for (let i = 0; i < days; i++) {
|
||||
const day = addDays(from, i);
|
||||
const dow = (new Date(`${day}T12:00:00Z`).getUTCDay() + 6) % 7;
|
||||
let label = "";
|
||||
if (scale === "day") label = fmt(day, { weekday: "narrow", day: "numeric" });
|
||||
else if (scale === "week" && dow === 0) label = fmt(day, { day: "numeric", month: "short" });
|
||||
else if (scale === "month" && day.endsWith("-01"))
|
||||
label = fmt(day, { month: "short", year: day.slice(5, 7) === "01" ? "numeric" : undefined });
|
||||
const weekend = dow >= 5 && scale !== "month";
|
||||
if (!label && !weekend) continue;
|
||||
const tick = h(
|
||||
"span",
|
||||
{
|
||||
class: `dw-db-tl__tick${label ? "" : " is-blank"}${weekend ? " is-weekend" : ""}`,
|
||||
style: { left: `${i * px}px`, width: `${px}px` },
|
||||
},
|
||||
label,
|
||||
);
|
||||
ticks.append(tick);
|
||||
}
|
||||
const todayAt = daysBetween(from, today);
|
||||
const marks = (): Node[] => {
|
||||
const out: Node[] = [];
|
||||
if (todayAt >= 0 && todayAt < days)
|
||||
out.push(
|
||||
h("span", { class: "dw-db-tl__today", style: { left: `${todayAt * px + px / 2}px` }, "aria-hidden": "true" }),
|
||||
);
|
||||
return out;
|
||||
};
|
||||
|
||||
const grid = h("div", { class: "dw-db-tl__grid" });
|
||||
grid.style.setProperty("--dw-tl-width", `${width}px`);
|
||||
grid.style.setProperty("--dw-tl-day", `${px}px`);
|
||||
grid.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "dw-db-tl__row dw-db-tl__row--head" },
|
||||
h("div", { class: "dw-db-tl__label" }),
|
||||
h("div", { class: "dw-db-tl__track" }, ticks, ...marks()),
|
||||
),
|
||||
);
|
||||
|
||||
for (const { r, span } of placed.slice(0, this.limit)) {
|
||||
const name = cellText(r, title) || l.untitledRow;
|
||||
const label = h("button", { type: "button", class: "dw-db-tl__label", title: name }, name);
|
||||
label.addEventListener("click", () => this.openRow(r.id));
|
||||
const track = h("div", { class: "dw-db-tl__track" }, ...marks());
|
||||
const a = daysBetween(from, span.from);
|
||||
const b = daysBetween(from, span.to) + 1;
|
||||
if (b > 0 && a < days) {
|
||||
const left = Math.max(a, 0);
|
||||
const right = Math.min(b, days);
|
||||
const bar = h(
|
||||
"div",
|
||||
{
|
||||
class: `dw-db-tl__bar${a < 0 ? " is-cut-start" : ""}${b > days ? " is-cut-end" : ""}${movable ? " is-movable" : ""}`,
|
||||
style: { left: `${left * px}px`, width: `${Math.max((right - left) * px, 4)}px` },
|
||||
role: "button",
|
||||
tabIndex: 0,
|
||||
title: `${name}: ${span.from === span.to ? span.from : `${span.from} – ${span.to}`}`,
|
||||
dataset: { row: r.id },
|
||||
},
|
||||
h("span", { class: "dw-db-tl__bar-text" }, name),
|
||||
);
|
||||
bar.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
this.openRow(r.id);
|
||||
}
|
||||
});
|
||||
const handle =
|
||||
movable && end && b <= days
|
||||
? h("span", { class: "dw-db-tl__handle", title: l.dragEnd, "aria-hidden": "true" })
|
||||
: null;
|
||||
if (handle) bar.append(handle);
|
||||
this.dragBar(
|
||||
bar,
|
||||
handle,
|
||||
px,
|
||||
(moved, resized) => {
|
||||
const store = this.host.store;
|
||||
if (!store) return;
|
||||
if (!moved && !resized) return this.openRow(r.id);
|
||||
store.tx(() => {
|
||||
if (resized) {
|
||||
const to = addDays(span.to, resized);
|
||||
if (end) store.setCell(r.id, end.id, to < span.from ? span.from : to);
|
||||
return;
|
||||
}
|
||||
store.setCell(r.id, start.id, addDays(span.from, moved));
|
||||
// A record with an end keeps its length.
|
||||
if (end && dateOf(cellValue(r, end))) store.setCell(r.id, end.id, addDays(span.to, moved));
|
||||
});
|
||||
},
|
||||
movable,
|
||||
);
|
||||
track.append(bar);
|
||||
}
|
||||
grid.append(h("div", { class: "dw-db-tl__row" }, label, track));
|
||||
}
|
||||
if (this.editable) {
|
||||
const add = h("button", { type: "button", class: "dw-db-t__new" }, icon("plus", 14), h("span", {}, l.newRow));
|
||||
add.addEventListener("click", () => this.addRow(start.type === "date" ? { [start.id]: today } : {}, true));
|
||||
grid.append(h("div", { class: "dw-db-tl__row dw-db-tl__row--new" }, add));
|
||||
}
|
||||
const scroller = h("div", { class: "dw-db-tl__scroll" }, grid);
|
||||
const children: Node[] = [nav, scroller];
|
||||
if (!rows.length) children.push(h("p", { class: "dw-db__empty" }, this.db.rows.length ? l.noMatches : l.noRows));
|
||||
if (placed.length > this.limit) {
|
||||
const more = h(
|
||||
"button",
|
||||
{ type: "button", class: "dw-db__btn dw-db__more" },
|
||||
`${l.more} (${placed.length - this.limit})`,
|
||||
);
|
||||
more.addEventListener("click", () => {
|
||||
this.limit += PAGE;
|
||||
this.drawBody();
|
||||
});
|
||||
children.push(more);
|
||||
}
|
||||
if (undated.length) {
|
||||
const chips = undated.slice(0, this.limit).map((r) => {
|
||||
const chip = h("button", { type: "button", class: "dw-db-c__chip" }, cellText(r, title) || l.untitledRow);
|
||||
chip.addEventListener("click", () => this.openRow(r.id));
|
||||
return chip;
|
||||
});
|
||||
children.push(
|
||||
h(
|
||||
"details",
|
||||
{ class: "dw-db-c__undated" },
|
||||
h("summary", {}, fill(l.noDate, undated.length)),
|
||||
h("div", { class: "dw-db-c__chips" }, chips),
|
||||
),
|
||||
);
|
||||
}
|
||||
this.body.replaceChildren(h("div", { class: "dw-db-tl" }, children));
|
||||
}
|
||||
|
||||
/**
|
||||
* Drags a timeline bar by whole days: the bar moves, or with the handle its
|
||||
* end. done gets the days moved and the days the end moved (both 0 for a
|
||||
* plain click or tap). Touch drags go sideways only, so the page still
|
||||
* scrolls up and down.
|
||||
*/
|
||||
private dragBar(
|
||||
bar: HTMLElement,
|
||||
handle: HTMLElement | null,
|
||||
px: number,
|
||||
done: (moved: number, resized: number) => void,
|
||||
movable: boolean,
|
||||
) {
|
||||
// The block around it is draggable; a bar must not start the browser's own drag.
|
||||
bar.addEventListener("dragstart", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
bar.addEventListener("pointerdown", (e) => {
|
||||
if (e.button !== 0) return;
|
||||
// No text selection or native drag from the mouse events that follow.
|
||||
if (e.pointerType === "mouse") e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const resizing = !!handle && (e.target as Node) === handle;
|
||||
const x0 = e.clientX;
|
||||
const y0 = e.clientY;
|
||||
const w0 = bar.offsetWidth;
|
||||
let days = 0;
|
||||
let dragging = false;
|
||||
try {
|
||||
bar.setPointerCapture(e.pointerId);
|
||||
} catch {
|
||||
// A pointer the browser no longer tracks; moves still reach the bar.
|
||||
}
|
||||
const move = (ev: PointerEvent) => {
|
||||
const dx = ev.clientX - x0;
|
||||
if (!dragging && Math.abs(dx) < 4) {
|
||||
// A finger moving up or down scrolls the page instead.
|
||||
if (Math.abs(ev.clientY - y0) > 8) cleanup();
|
||||
return;
|
||||
}
|
||||
if (!movable) return;
|
||||
dragging = true;
|
||||
days = Math.round(dx / px);
|
||||
bar.classList.add("is-dragging");
|
||||
if (resizing) bar.style.width = `${Math.max(w0 + days * px, px)}px`;
|
||||
else bar.style.transform = `translateX(${days * px}px)`;
|
||||
};
|
||||
const cleanup = () => {
|
||||
bar.removeEventListener("pointermove", move);
|
||||
bar.removeEventListener("pointerup", up);
|
||||
bar.removeEventListener("pointercancel", cancel);
|
||||
if (bar.hasPointerCapture(e.pointerId)) bar.releasePointerCapture(e.pointerId);
|
||||
};
|
||||
const up = () => {
|
||||
cleanup();
|
||||
bar.classList.remove("is-dragging");
|
||||
bar.style.transform = "";
|
||||
if (resizing) bar.style.width = `${w0}px`;
|
||||
if (!dragging) done(0, 0);
|
||||
else if (days) done(resizing ? 0 : days, resizing ? days : 0);
|
||||
};
|
||||
const cancel = () => {
|
||||
cleanup();
|
||||
bar.classList.remove("is-dragging");
|
||||
bar.style.transform = "";
|
||||
bar.style.width = `${w0}px`;
|
||||
};
|
||||
bar.addEventListener("pointermove", move);
|
||||
bar.addEventListener("pointerup", up);
|
||||
bar.addEventListener("pointercancel", cancel);
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- calendar
|
||||
|
||||
private drawCalendar(v: View) {
|
||||
@@ -1589,6 +1907,8 @@ const fallbackView: View = {
|
||||
groupBy: null,
|
||||
dateColumn: null,
|
||||
cover: null,
|
||||
endColumn: null,
|
||||
scale: "week",
|
||||
widths: {},
|
||||
};
|
||||
|
||||
@@ -1599,6 +1919,7 @@ const viewIcons: Record<ViewType, IconName> = {
|
||||
calendar: "calendar",
|
||||
list: "list",
|
||||
gallery: "grid",
|
||||
timeline: "timeline",
|
||||
};
|
||||
|
||||
/** Layouts the Group button applies to (kanban always groups, in its settings). */
|
||||
|
||||
@@ -1902,6 +1902,199 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Timeline view ---- */
|
||||
.dw-db-tl {
|
||||
padding-top: 8px;
|
||||
}
|
||||
.dw-db-tl__zoom {
|
||||
display: inline-flex;
|
||||
margin-left: 8px;
|
||||
border: 1px solid var(--color-line);
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
}
|
||||
.dw-db-tl__zoom .dw-db__btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
.dw-db-tl__zoom .dw-db__btn.is-on {
|
||||
background: var(--color-accent-soft);
|
||||
color: var(--color-ink);
|
||||
}
|
||||
.dw-db-tl__scroll {
|
||||
overflow-x: auto;
|
||||
border: 1px solid var(--color-line);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
.dw-db-tl__grid {
|
||||
--dw-tl-label: 180px;
|
||||
width: calc(var(--dw-tl-label) + var(--dw-tl-width));
|
||||
}
|
||||
.dw-db-tl__row {
|
||||
display: flex;
|
||||
height: 34px;
|
||||
border-bottom: 1px solid var(--color-line);
|
||||
}
|
||||
.dw-db-tl__row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.dw-db-tl__row--head {
|
||||
height: 30px;
|
||||
background: var(--color-surface-sunken);
|
||||
}
|
||||
.dw-db-tl__row--new {
|
||||
height: auto;
|
||||
}
|
||||
.dw-db-tl__row--new .dw-db-t__new {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
width: var(--dw-tl-label);
|
||||
}
|
||||
.dw-db-tl__label {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
z-index: 2;
|
||||
flex: 0 0 var(--dw-tl-label);
|
||||
overflow: hidden;
|
||||
padding: 0 10px;
|
||||
border: none;
|
||||
border-right: 1px solid var(--color-line);
|
||||
background: var(--color-surface);
|
||||
color: var(--color-ink);
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
line-height: 34px;
|
||||
text-align: left;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
.dw-db-tl__row--head .dw-db-tl__label {
|
||||
background: var(--color-surface-sunken);
|
||||
cursor: default;
|
||||
}
|
||||
.dw-db-tl__track {
|
||||
position: relative;
|
||||
flex: 0 0 var(--dw-tl-width);
|
||||
/* A faint line between days at the larger scales. */
|
||||
background-image: linear-gradient(to right, var(--color-line) 1px, transparent 1px);
|
||||
background-size: calc(var(--dw-tl-day) * 7) 100%;
|
||||
}
|
||||
.dw-db-tl__ticks {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
.dw-db-tl__tick {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
overflow: visible;
|
||||
padding: 0 4px;
|
||||
color: var(--color-ink-muted);
|
||||
font-size: 11px;
|
||||
line-height: 30px;
|
||||
white-space: nowrap;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
.dw-db-tl__tick.is-weekend {
|
||||
background: rgb(0 0 0 / 0.04);
|
||||
}
|
||||
.dw-db-tl__today {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 2px;
|
||||
margin-left: -1px;
|
||||
background: var(--color-accent);
|
||||
opacity: 0.6;
|
||||
pointer-events: none;
|
||||
}
|
||||
.dw-db-tl__bar {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
height: 22px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-accent-soft);
|
||||
box-shadow: inset 0 0 0 1px var(--color-accent);
|
||||
color: var(--color-ink);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
touch-action: pan-y;
|
||||
user-select: none;
|
||||
}
|
||||
.dw-db-tl__bar.is-cut-start {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
.dw-db-tl__bar.is-cut-end {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
.dw-db-tl__bar.is-movable {
|
||||
cursor: grab;
|
||||
}
|
||||
.dw-db-tl__bar.is-dragging {
|
||||
z-index: 3;
|
||||
cursor: grabbing;
|
||||
box-shadow:
|
||||
inset 0 0 0 2px var(--color-accent),
|
||||
0 2px 6px rgb(0 0 0 / 0.15);
|
||||
}
|
||||
.dw-db-tl__bar:focus-visible {
|
||||
outline: 2px solid var(--color-focus-ring);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
.dw-db-tl__bar-text {
|
||||
overflow: hidden;
|
||||
padding: 0 6px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.dw-db-tl__handle {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: 8px;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.dw-db-tl__handle::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
bottom: 5px;
|
||||
right: 3px;
|
||||
width: 2px;
|
||||
border-radius: 1px;
|
||||
background: var(--color-accent);
|
||||
opacity: 0;
|
||||
}
|
||||
.dw-db-tl__bar:hover .dw-db-tl__handle::after {
|
||||
opacity: 1;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.dw-db-tl__grid {
|
||||
--dw-tl-label: 110px;
|
||||
}
|
||||
.dw-db-tl__zoom {
|
||||
margin-left: 0;
|
||||
}
|
||||
.dw-db-tl .dw-db-c__nav {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
@media (hover: none) {
|
||||
/* A wider grip for a finger, always visible. */
|
||||
.dw-db-tl__handle {
|
||||
width: 16px;
|
||||
}
|
||||
.dw-db-tl__handle::after {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Kanban view ---- */
|
||||
.dw-db-k {
|
||||
display: flex;
|
||||
|
||||
@@ -124,6 +124,8 @@ export const iconPaths = {
|
||||
tag: ["M4 4h7l9 9-7 7-9-9z", "M8 8h.01"],
|
||||
grid: ["M4 4h7v7H4z", "M13 4h7v7h-7z", "M4 13h7v7H4z", "M13 13h7v7h-7z"],
|
||||
cards: ["M4 5h16v6H4z", "M4 15h16v4H4z"],
|
||||
timeline: ["M4 4v16", "M7 7h8", "M10 12h10", "M7 17h6"],
|
||||
chart: ["M4 20h16", "M7 16v-5", "M12 16V6", "M17 16v-8"],
|
||||
filter: ["M4 5h16l-6 8v6l-4-2v-4z"],
|
||||
layers: ["M12 4l8 4-8 4-8-4z", "M4 12l8 4 8-4", "M4 16l8 4 8-4"],
|
||||
journal: ["M6 3h11a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6z", "M9 3v18", "M12 8h3", "M12 12h3"],
|
||||
|
||||
@@ -906,7 +906,17 @@
|
||||
"viewList": "Liste",
|
||||
"viewGallery": "Galerie",
|
||||
"cover": "Kartenbild",
|
||||
"noCover": "Kein Bild"
|
||||
"noCover": "Kein Bild",
|
||||
"viewTimeline": "Zeitleiste",
|
||||
"endColumn": "Enddatum-Eigenschaft",
|
||||
"sameDay": "Am selben Tag wie der Beginn",
|
||||
"scaleDay": "Tage",
|
||||
"scaleWeek": "Wochen",
|
||||
"scaleMonth": "Monate",
|
||||
"earlier": "Früher",
|
||||
"later": "Später",
|
||||
"noStartColumn": "Füge eine Datumseigenschaft hinzu, um Einträge auf der Zeitleiste anzuordnen.",
|
||||
"dragEnd": "Ziehen, um das Enddatum zu ändern"
|
||||
},
|
||||
"edgeless": {
|
||||
"toolbar": "Werkzeuge der Tafel",
|
||||
|
||||
@@ -906,7 +906,17 @@
|
||||
"viewList": "List",
|
||||
"viewGallery": "Gallery",
|
||||
"cover": "Card cover",
|
||||
"noCover": "No cover"
|
||||
"noCover": "No cover",
|
||||
"viewTimeline": "Timeline",
|
||||
"endColumn": "End date property",
|
||||
"sameDay": "Same day as the start",
|
||||
"scaleDay": "Days",
|
||||
"scaleWeek": "Weeks",
|
||||
"scaleMonth": "Months",
|
||||
"earlier": "Earlier",
|
||||
"later": "Later",
|
||||
"noStartColumn": "Add a date property to place records on the timeline.",
|
||||
"dragEnd": "Drag to change the end date"
|
||||
},
|
||||
"edgeless": {
|
||||
"toolbar": "Canvas tools",
|
||||
|
||||
@@ -906,7 +906,17 @@
|
||||
"viewList": "Lista",
|
||||
"viewGallery": "Galería",
|
||||
"cover": "Portada de la tarjeta",
|
||||
"noCover": "Sin portada"
|
||||
"noCover": "Sin portada",
|
||||
"viewTimeline": "Cronograma",
|
||||
"endColumn": "Propiedad de fecha de fin",
|
||||
"sameDay": "El mismo día que el inicio",
|
||||
"scaleDay": "Días",
|
||||
"scaleWeek": "Semanas",
|
||||
"scaleMonth": "Meses",
|
||||
"earlier": "Antes",
|
||||
"later": "Después",
|
||||
"noStartColumn": "Añade una propiedad de fecha para colocar los registros en el cronograma.",
|
||||
"dragEnd": "Arrastra para cambiar la fecha de fin"
|
||||
},
|
||||
"edgeless": {
|
||||
"toolbar": "Herramientas del lienzo",
|
||||
|
||||
@@ -906,7 +906,17 @@
|
||||
"viewList": "Liste",
|
||||
"viewGallery": "Galerie",
|
||||
"cover": "Couverture des cartes",
|
||||
"noCover": "Pas de couverture"
|
||||
"noCover": "Pas de couverture",
|
||||
"viewTimeline": "Chronologie",
|
||||
"endColumn": "Propriété de date de fin",
|
||||
"sameDay": "Même jour que le début",
|
||||
"scaleDay": "Jours",
|
||||
"scaleWeek": "Semaines",
|
||||
"scaleMonth": "Mois",
|
||||
"earlier": "Plus tôt",
|
||||
"later": "Plus tard",
|
||||
"noStartColumn": "Ajoutez une propriété de date pour placer les enregistrements sur la chronologie.",
|
||||
"dragEnd": "Faites glisser pour changer la date de fin"
|
||||
},
|
||||
"edgeless": {
|
||||
"toolbar": "Outils du tableau",
|
||||
|
||||
@@ -906,7 +906,17 @@
|
||||
"viewList": "Lista",
|
||||
"viewGallery": "Galeria",
|
||||
"cover": "Okładka karty",
|
||||
"noCover": "Bez okładki"
|
||||
"noCover": "Bez okładki",
|
||||
"viewTimeline": "Oś czasu",
|
||||
"endColumn": "Właściwość daty końca",
|
||||
"sameDay": "Ten sam dzień co początek",
|
||||
"scaleDay": "Dni",
|
||||
"scaleWeek": "Tygodnie",
|
||||
"scaleMonth": "Miesiące",
|
||||
"earlier": "Wcześniej",
|
||||
"later": "Później",
|
||||
"noStartColumn": "Dodaj właściwość daty, aby umieścić rekordy na osi czasu.",
|
||||
"dragEnd": "Przeciągnij, aby zmienić datę końca"
|
||||
},
|
||||
"edgeless": {
|
||||
"toolbar": "Narzędzia tablicy",
|
||||
|
||||
Reference in new issue
Block a user