Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

spaces: a view is about a set of pages, and can be looked at as a table (#389)

nyblnete134ffb5af25
diff --git a/scripts/test-spaces-model.ts b/scripts/test-spaces-model.ts
index ee0c7f4b..c0fe24c2 100644
--- a/scripts/test-spaces-model.ts
+++ b/scripts/test-spaces-model.ts
@@ -478,6 +478,41 @@ for (const [label, input, err] of [
ok(/openAddProperty\(page\.id, addProp\)/.test(props), 'the properties panel offers it')
}
+// ---- a view is about a set of pages, and can be looked at as a table -------
+// A view meant ONE thing: every page carrying a `status`. That made the tracker
+// work and everything else impossible — no "the pages with an Author", no "the
+// pages under Books", so a space could hold a backlog and never a reading list.
+//
+// ABSENT MEANS ISSUES. That is the compatibility rule, not a default: every
+// view block written before `source` existed carries none and must keep showing
+// the backlog forever, and a view set back to Issues must be byte-identical to
+// one that never moved — the same rule `filter` already follows.
+{
+ const fs = await import('node:fs')
+ const fields = fs.readFileSync(new URL('../spaces/src/fields.ts', import.meta.url), 'utf8')
+ const render = fs.readFileSync(new URL('../spaces/src/render.ts', import.meta.url), 'utf8')
+ const ed = fs.readFileSync(new URL('../spaces/src/editor.ts', import.meta.url), 'utf8')
+
+ ok(/export function viewRows\(/.test(fields), 'a view selects its rows through one function')
+ ok(/if \(!has && !under\) return issuesOf\(doc\)/.test(fields),
+ '…and with no source it is still the backlog, so old view blocks are unchanged')
+ ok(/viewRows\(doc, \(b as \{ source\?: unknown \}\)\.source\)/.test(render),
+ 'the renderer asks for the block\'s own source rather than the issues')
+
+ // The table is the shape a base is usually looked at in. Its columns must
+ // come from the ROWS, not the vocabulary: a table of books carrying no
+ // Estimate should not grow an Estimate column because the schema has one.
+ ok(/layout === 'table'/.test(render), 'a view can be a table')
+ ok(/rows\.some\(\(r\) => r\.values\.has\(k\)\)/.test(render),
+ '…whose columns are the fields the rows actually carry')
+ ok(/overflow-x/.test(fs.readFileSync(new URL('../spaces/src/styles.css', import.meta.url), 'utf8')
+ .split('.sp-view-tablewrap')[1]?.slice(0, 120) ?? ''),
+ '…and scrolls inside itself, so a wide table never scrolls the page sideways')
+
+ // Cycling all the way round must leave the block as it started.
+ ok(/table: undefined/.test(ed), 'cycling past table clears the key rather than storing "board"')
+}
+
// ---- find & replace: the number shown IS the number changed ----------------
// Replace-all is destructive and lands in one commit, so the count in the
// readout, the count in the confirmation and the count of things that change
diff --git a/spaces/src/editor.ts b/spaces/src/editor.ts
index 60e94ecd..8d986f06 100644
--- a/spaces/src/editor.ts
+++ b/spaces/src/editor.ts
@@ -1515,6 +1515,8 @@ export class Editor {
gb?.addEventListener('click', () => this.openViewGroup(v.dataset.blockId!, gb))
const sb = v.querySelector<HTMLElement>('[data-view-sort]')
sb?.addEventListener('click', () => this.openViewSort(v.dataset.blockId!, sb))
+ const srcB = v.querySelector<HTMLElement>('[data-view-source]')
+ srcB?.addEventListener('click', () => this.openViewSource(v.dataset.blockId!, srcB))
// A SORTED BOARD HAS NO HAND ORDER TO DROP INTO. The sort decides where a
// card sits, so offering a drop position would write an order into
@@ -1691,7 +1693,7 @@ export class Editor {
* list and back is byte-identical to one that was never touched, and a file
* written before this control existed stays that way.
*/
- private editView(blockId: string, key: 'layout' | 'groupBy' | 'sort', value: unknown): void {
+ private editView(blockId: string, key: 'layout' | 'groupBy' | 'sort' | 'source', value: unknown): void {
const s = this.store
const b = s.block(blockId)
if (!b || s.readOnly || this.reading) return
@@ -1704,10 +1706,57 @@ export class Editor {
}
/** Board ⇄ list. `board` is the default, so it is stored as an ABSENT key. */
+ /**
+ * WHICH PAGES A VIEW HOLDS.
+ *
+ * The answer used to be one thing — every page carrying a `status` — which
+ * is why a space could hold a backlog and nothing else. Two selectors now,
+ * and only two: the pages carrying a given property, or the pages under a
+ * given page. With a flat vocabulary where each page carries only the fields
+ * it uses, "has an Author" IS "is a book".
+ *
+ * Issues stays the ABSENT key, so every view written before this keeps
+ * showing the backlog and a view set back to Issues is byte-identical to one
+ * that never moved.
+ */
+ private openViewSource(blockId: string, anchor: HTMLElement): void {
+ const s = this.store
+ const b = s.block(blockId)
+ if (!b) return
+ this.popover(anchor, (pop) => {
+ const set = (src: { has?: string; under?: string } | undefined) => {
+ this.editView(blockId, 'source', src)
+ this.closeOverlay()
+ }
+ pop.append(el('div', 'sp-pop-title', t('Which pages')))
+ pop.append(this.menuItem('board', t('Issues'), t('Every page with a status'), () => set(undefined)))
+
+ // A property somebody invented is the interesting case, so it comes
+ // first among the fields and lists every one the vocabulary has.
+ for (const f of fieldsOf(s.doc)) {
+ pop.append(this.menuItem('tag', f.label, t('Pages that have this property'),
+ () => set({ has: f.key })))
+ }
+
+ // Nesting is how a space is already organised, so the current page and
+ // its ancestors are the ones worth offering rather than every page.
+ const here = s.page
+ if (here) {
+ pop.append(el('div', 'sp-pop-title', t('Nested under')))
+ pop.append(this.menuItem('page', here.title || t('Untitled'),
+ t('Pages nested under this one'), () => set({ under: here.id })))
+ }
+ })
+ }
+
private toggleViewLayout(blockId: string): void {
const b = this.store.block(blockId)
const now = String((b as { layout?: unknown } | undefined)?.layout ?? 'board')
- this.editView(blockId, 'layout', now === 'list' ? undefined : 'list')
+ // Board -> list -> table -> board. `board` is the ABSENT key, never a
+ // stored 'board': a view cycled all the way round is byte-identical to one
+ // nobody ever touched, which is the same rule filter and source follow.
+ const next: Record<string, string | undefined> = { board: 'list', list: 'table', table: undefined }
+ this.editView(blockId, 'layout', next[now] ?? (now === 'table' ? undefined : 'list'))
}
/**
diff --git a/spaces/src/fields.ts b/spaces/src/fields.ts
index 63601c76..f32ba303 100644
--- a/spaces/src/fields.ts
+++ b/spaces/src/fields.ts
@@ -393,6 +393,74 @@ export function issuesOf(doc: SpacesDoc): IssueRow[] {
return out
}
+/**
+ * WHICH PAGES A VIEW IS ABOUT.
+ *
+ * A view used to mean one thing: every page carrying a `status`. That made the
+ * tracker work and made everything else impossible — a space could hold a
+ * backlog and never a reading list, because there was no way to say "the pages
+ * with an Author" or "the pages under Books".
+ *
+ * ABSENT MEANS ISSUES, and that is the compatibility rule rather than a
+ * default: every `view` block written before this existed carries no `source`
+ * and must keep showing the backlog forever. The editor DELETES the key rather
+ * than storing an empty object, so a view whose source was set and cleared is
+ * byte-identical to one that never had it.
+ *
+ * Two selectors, and deliberately only two. `has` is the one that pairs with a
+ * property somebody just invented — the vocabulary is flat and a page carries
+ * only the fields it uses, so "has an Author" IS "is a book". `under` is the
+ * one people reach for anyway, because nesting is how a space is already
+ * organised. A selector language grows without limit and can never shrink:
+ * every operator ships permanently into files on other people's disks.
+ */
+export interface ViewSource {
+ /** pages carrying this field */
+ has?: string
+ /** pages nested anywhere under this page */
+ under?: string
+}
+
+export const unknownSourceKeys = (src: unknown): string[] =>
+ !src || typeof src !== 'object' ? []
+ : Object.keys(src as Record<string, unknown>).filter((k) => k !== 'has' && k !== 'under')
+
+/** Is this page anywhere below `root`? Cycle-safe, like the tree walk. */
+function isUnder(doc: SpacesDoc, page: Page, root: string): boolean {
+ const seen = new Set<string>()
+ let cur: string | undefined = page.parent
+ while (cur && !seen.has(cur)) {
+ if (cur === root) return true
+ seen.add(cur)
+ cur = doc.pages.find((p) => p.id === cur)?.parent
+ }
+ return false
+}
+
+/**
+ * The rows a view holds.
+ *
+ * Derived every render from the pages themselves — never stored — for the same
+ * reason the board's order is `doc.pages`: a database that keeps its own copy
+ * of the rows is a database that disagrees with the document.
+ */
+export function viewRows(doc: SpacesDoc, source?: unknown): IssueRow[] {
+ const src = (source && typeof source === 'object' ? source : {}) as ViewSource
+ const has = typeof src.has === 'string' ? src.has : ''
+ const under = typeof src.under === 'string' ? src.under : ''
+ if (!has && !under) return issuesOf(doc)
+
+ const out: IssueRow[] = []
+ for (const page of doc.pages) {
+ if (page.archived) continue
+ if (under && !isUnder(doc, page, under)) continue
+ const values = valuesOf(page)
+ if (has && !values.has(has)) continue
+ out.push({ page, values })
+ }
+ return out
+}
+
/** Where a dropped card lands: before a card, or after the last one. */
export interface DropAim { before?: string; after?: string }
diff --git a/spaces/src/i18n/de.ts b/spaces/src/i18n/de.ts
index 2fe19dbe..8f3fc2da 100644
--- a/spaces/src/i18n/de.ts
+++ b/spaces/src/i18n/de.ts
@@ -594,4 +594,10 @@ export const de: Catalog = {
"Added {name}": "{name} hinzugefügt",
"Name": "Name",
"New property": "Neue Eigenschaft",
+ "Choose which pages this view holds": "Wählen, welche Seiten diese Ansicht enthält",
+ "Every page with a status": "Jede Seite mit einem Status",
+ "Nested under": "Verschachtelt unter",
+ "Pages nested under this one": "Seiten unterhalb dieser Seite",
+ "Pages that have this property": "Seiten mit dieser Eigenschaft",
+ "Which pages": "Welche Seiten",
}
diff --git a/spaces/src/i18n/es.ts b/spaces/src/i18n/es.ts
index 5f248b0f..856bc060 100644
--- a/spaces/src/i18n/es.ts
+++ b/spaces/src/i18n/es.ts
@@ -594,4 +594,10 @@ export const es: Catalog = {
"Added {name}": "Se añadió {name}",
"Name": "Nombre",
"New property": "Nueva propiedad",
+ "Choose which pages this view holds": "Elige qué páginas contiene esta vista",
+ "Every page with a status": "Todas las páginas con estado",
+ "Nested under": "Anidadas en",
+ "Pages nested under this one": "Páginas anidadas bajo esta",
+ "Pages that have this property": "Páginas que tienen esta propiedad",
+ "Which pages": "Qué páginas",
}
diff --git a/spaces/src/i18n/fr.ts b/spaces/src/i18n/fr.ts
index 431caaaf..29628492 100644
--- a/spaces/src/i18n/fr.ts
+++ b/spaces/src/i18n/fr.ts
@@ -594,4 +594,10 @@ export const fr: Catalog = {
"Added {name}": "{name} ajoutée",
"Name": "Nom",
"New property": "Nouvelle propriété",
+ "Choose which pages this view holds": "Choisir les pages que contient cette vue",
+ "Every page with a status": "Toutes les pages ayant un statut",
+ "Nested under": "Imbriquées sous",
+ "Pages nested under this one": "Pages imbriquées sous celle-ci",
+ "Pages that have this property": "Pages qui ont cette propriété",
+ "Which pages": "Quelles pages",
}
diff --git a/spaces/src/i18n/it.ts b/spaces/src/i18n/it.ts
index cd97b205..67055323 100644
--- a/spaces/src/i18n/it.ts
+++ b/spaces/src/i18n/it.ts
@@ -594,4 +594,10 @@ export const it: Catalog = {
"Added {name}": "{name} aggiunta",
"Name": "Nome",
"New property": "Nuova proprietà",
+ "Choose which pages this view holds": "Scegli quali pagine contiene questa vista",
+ "Every page with a status": "Ogni pagina con uno stato",
+ "Nested under": "Annidate sotto",
+ "Pages nested under this one": "Pagine annidate sotto questa",
+ "Pages that have this property": "Pagine che hanno questa proprietà",
+ "Which pages": "Quali pagine",
}
diff --git a/spaces/src/i18n/ja.ts b/spaces/src/i18n/ja.ts
index d2668746..c7f05edc 100644
--- a/spaces/src/i18n/ja.ts
+++ b/spaces/src/i18n/ja.ts
@@ -594,4 +594,10 @@ export const ja: Catalog = {
"Added {name}": "{name} を追加しました",
"Name": "名前",
"New property": "新しいプロパティ",
+ "Choose which pages this view holds": "このビューに入れるページを選ぶ",
+ "Every page with a status": "ステータスを持つすべてのページ",
+ "Nested under": "この下のページ",
+ "Pages nested under this one": "このページの下にあるページ",
+ "Pages that have this property": "このプロパティを持つページ",
+ "Which pages": "どのページ",
}
diff --git a/spaces/src/i18n/packed.ts b/spaces/src/i18n/packed.ts
index 70d06478..38585383 100644
--- a/spaces/src/i18n/packed.ts
+++ b/spaces/src/i18n/packed.ts
@@ -66,7 +66,6 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Block options": ["ブロックのオプション","块选项","區塊選項","Opciones del bloque","Options du bloc","Block-Optionen","Opzioni del blocco","Opções do bloco"],
"Blocks": ["ブロック","块","區塊","Bloques","Blocs","Blöcke","Blocchi","Blocos"],
"Blue": ["青","蓝色","藍色","Azul","Bleu","Blau","Blu","Azul"],
- "Board": ["ボード","看板","看板","Tablero","Tableau","Board","Bacheca","Quadro"],
"Board or list": ["ボードまたはリスト","看板或列表","看板或清單","Tablero o lista","Tableau ou liste","Board oder Liste","Bacheca o elenco","Quadro ou lista"],
"Bold": ["ボールド","粗体","粗體","Negrita","Gras","Fett","Grassetto","Negrito"],
"Bold — ⌘B": ["ボールド — ⌘B","粗体 — ⌘B","粗體 — ⌘B","Negrita — ⌘B","Gras — ⌘B","Fett — ⌘B","Grassetto — ⌘B","Negrito — ⌘B"],
@@ -97,6 +96,7 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Choose a space…": ["スペースを選ぶ…","选择一个空间…","選擇一個空間…","Elegir un espacio…","Choisir un espace…","Space auswählen…","Scegli uno spazio…","Escolher um espaço…"],
"Choose the field the columns come from": ["列のもとになるフィールドを選ぶ","选择用作分栏的字段","選擇作為欄的欄位","Elige el campo del que salen las columnas","Choisir le champ dont viennent les colonnes","Feld wählen, aus dem die Spalten kommen","Scegli il campo da cui nascono le colonne","Escolha o campo de onde vêm as colunas"],
"Choose the order": ["並び順を選ぶ","选择排序方式","選擇排序方式","Elige el orden","Choisir l’ordre","Reihenfolge wählen","Scegli l’ordine","Escolha a ordem"],
+ "Choose which pages this view holds": ["このビューに入れるページを選ぶ","选择此视图包含哪些页面","選擇此檢視包含哪些頁面","Elige qué páginas contiene esta vista","Choisir les pages que contient cette vue","Wählen, welche Seiten diese Ansicht enthält","Scegli quali pagine contiene questa vista","Escolhe que páginas esta vista contém"],
"Clear filter": ["フィルターを解除","清除筛选","清除篩選","Borrar el filtro","Effacer le filtre","Filter zurücksetzen","Azzera il filtro","Limpar o filtro"],
"Clear formatting": ["書式をクリア","清除格式","清除格式","Borrar formato","Effacer la mise en forme","Formatierung entfernen","Cancella formattazione","Limpar formatação"],
"Clip added ({size})": ["クリップを追加しました({size})","已添加片段 ({size})","已新增片段 ({size})","Clip añadido ({size})","Clip ajouté ({size})","Clip hinzugefügt ({size})","Clip aggiunta ({size})","Clipe adicionado ({size})"],
@@ -160,6 +160,7 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Embedded in the file": ["ファイルに埋め込み済み","已嵌入文件","已嵌入檔案","Incrustado en el archivo","Intégré au fichier","In der Datei eingebettet","Incorporato nel file","Embutido no arquivo"],
"Enter the password to open it.": ["開くにはパスワードを入力してください。","输入密码以打开。","請輸入密碼以開啟。","Introduce la contraseña para abrirlo.","Saisissez le mot de passe pour l’ouvrir.","Gib das Passwort ein, um ihn zu öffnen.","Inserisci la password per aprirlo.","Introduza a palavra-passe para o abrir."],
"Every page opens wide on this screen from now on": ["この画面では今後すべてのページを広く表示します","在此屏幕上,之后所有页面都会以加宽方式打开","在此螢幕上,之後所有頁面都會以加寬方式開啟","A partir de ahora todas las páginas se abren anchas en esta pantalla","Désormais toutes les pages s’ouvrent en large sur cet écran","Auf diesem Bildschirm öffnen ab jetzt alle Seiten breit","Da ora tutte le pagine si aprono larghe su questo schermo","A partir de agora todas as páginas abrem largas neste ecrã"],
+ "Every page with a status": ["ステータスを持つすべてのページ","所有带状态的页面","所有帶狀態的頁面","Todas las páginas con estado","Toutes les pages ayant un statut","Jede Seite mit einem Status","Ogni pagina con uno stato","Todas as páginas com estado"],
"Every page, as one .md file": ["すべてのページを 1 つの .md ファイルに","所有页面合并为一个 .md 文件","所有頁面合併為一個 .md 檔","Todas las páginas, en un solo archivo .md","Toutes les pages, en un seul fichier .md","Jede Seite, in einer .md-Datei","Tutte le pagine, in un unico file .md","Todas as páginas num único ficheiro .md"],
"Everything in this space is replaced by what you paste. ⌘Z undoes it, but only while this window stays open.": ["このスペースの内容はすべて貼り付けた内容に置き換わります。⌘Z で元に戻せますが、それはこのウィンドウを開いている間だけです。","这个空间里的所有内容都会被你粘贴的内容替换。⌘Z 可以撤销,但仅限于这个窗口保持打开时。","這個空間裡的所有內容都會被你貼上的內容取代。⌘Z 可以復原,但僅限於這個視窗保持開啟時。","Todo lo que hay en este espacio se sustituye por lo que pegues. ⌘Z lo deshace, pero solo mientras esta ventana siga abierta.","Tout ce que contient cet espace est remplacé par ce que vous collez. ⌘Z annule l’opération, mais seulement tant que cette fenêtre reste ouverte.","Alles in diesem Space wird durch das ersetzt, was Sie einfügen. ⌘Z macht das rückgängig, aber nur solange dieses Fenster geöffnet bleibt.","Tutto ciò che si trova in questo spazio viene sostituito da quello che incolli. ⌘Z annulla l’operazione, ma solo finché questa finestra resta aperta.","Tudo o que está neste espaço é substituído pelo que colar. ⌘Z desfaz, mas só enquanto esta janela continuar aberta."],
"Export": ["書き出す","导出","匯出","Exportar","Exporter","Exportieren","Esporta","Exportar"],
@@ -242,7 +243,6 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Linked": ["リンク","链接","連結","Enlazado","Lié","Verknüpft","Collegata","Externo"],
"Linked from": ["リンク元","链接来源","連結來源","Enlazado desde","Liens entrants","Verlinkt von","Collegata da","Ligado a partir de"],
"Links to it become dead": ["このページへのリンクが切れます","指向它的链接会失效","指向它的連結會失效","Los enlaces a ella dejan de funcionar","Les liens vers elle seront rompus","Links darauf laufen ins Leere","I collegamenti a questa pagina si interrompono","As ligações para ela ficam quebradas"],
- "List": ["リスト","列表","清單","Lista","Liste","Liste","Elenco","Lista"],
"Live": ["ライブ","已连接","已連線","En vivo","En direct","Live","Dal vivo","Ao vivo"],
"Live — nobody else is here yet": ["ライブ中 — まだほかに誰もいません","实时协作中 — 还没有其他人","即時協作中 — 還沒有其他人","En directo — todavía no hay nadie más","En direct — personne d’autre pour l’instant","Live — noch niemand sonst da","In diretta — non c’è ancora nessun altro","Ao vivo — ainda não há mais ninguém"],
"Live — send someone the file to bring them in": ["ライブ中 — ファイルを送れば参加できます","实时协作中 — 把文件发给别人即可加入","即時協作中 — 把檔案傳給別人即可加入","En directo — envía el archivo a alguien para que entre","En direct — envoyez le fichier à quelqu’un pour qu’il rejoigne","Live — schick jemandem die Datei, dann ist er dabei","In diretta — manda il file a qualcuno per farlo entrare","Ao vivo — envie o ficheiro a alguém para essa pessoa entrar"],
@@ -260,6 +260,7 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Move up": ["上へ移動","上移","上移","Subir","Monter","Nach oben","Sposta su","Mover para cima"],
"Muted": ["ミュート","静音","靜音","Silenciado","Muet","Stumm","Muto","Sem som"],
"Name": ["名前","名称","名稱","Nombre","Nom","Name","Nome","Nome"],
+ "Nested under": ["この下のページ","嵌套于","巢狀於","Anidadas en","Imbriquées sous","Verschachtelt unter","Annidate sotto","Aninhadas em"],
"New issue": ["新しいイシュー","新建事项","新增項目","Nueva incidencia","Nouveau ticket","Neues Issue","Nuova issue","Nova tarefa"],
"New page": ["新規ページ","新建页面","新增頁面","Nueva página","Nouvelle page","Neue Seite","Nuova pagina","Nova página"],
"New page (⌘⌥N)": ["新規ページ (⌘⌥N)","新建页面 (⌘⌥N)","新增頁面 (⌘⌥N)","Nueva página (⌘⌥N)","Nouvelle page (⌘⌥N)","Neue Seite (⌘⌥N)","Nuova pagina (⌘⌥N)","Nova página (⌘⌥N)"],
@@ -303,7 +304,9 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Page": ["ページ","页面","頁面","Página","Page","Seite","Pagina","Página"],
"Page options": ["ページのオプション","页面选项","頁面選項","Opciones de la página","Options de la page","Seiten-Optionen","Opzioni della pagina","Opções da página"],
"Pages": ["ページ","页面","頁面","Páginas","Pages","Seiten","Pagine","Páginas"],
+ "Pages nested under this one": ["このページの下にあるページ","嵌套在此页面下的页面","巢狀在此頁面下的頁面","Páginas anidadas bajo esta","Pages imbriquées sous celle-ci","Seiten unterhalb dieser Seite","Pagine annidate sotto questa","Páginas aninhadas sob esta"],
"Pages open at their normal width again": ["ページは通常の幅に戻りました","页面已恢复为正常宽度","頁面已恢復為正常寬度","Las páginas vuelven a su anchura normal","Les pages retrouvent leur largeur normale","Seiten öffnen wieder in normaler Breite","Le pagine tornano alla larghezza normale","As páginas voltam à largura normal"],
+ "Pages that have this property": ["このプロパティを持つページ","具有此属性的页面","具有此屬性的頁面","Páginas que tienen esta propiedad","Pages qui ont cette propriété","Seiten mit dieser Eigenschaft","Pagine che hanno questa proprietà","Páginas que têm esta propriedade"],
"Pages — show or hide the page list": ["ページ — ページ一覧の表示/非表示","页面 — 显示或隐藏页面列表","頁面 — 顯示或隱藏頁面清單","Páginas — mostrar u ocultar la lista de páginas","Pages — afficher ou masquer la liste","Seiten — Seitenliste ein- oder ausblenden","Pagine — mostra o nascondi l’elenco delle pagine","Páginas — mostrar ou ocultar a lista de páginas"],
"Password": ["パスワード","密码","密碼","Contraseña","Mot de passe","Passwort","Password","Palavra-passe"],
"Password removed. Save to write the space unencrypted.": ["パスワードを削除しました。保存すると、このスペースは暗号化なしで書き込まれます。","已移除密码。保存后空间将以未加密方式写入。","已移除密碼。儲存後空間將以未加密方式寫入。","Contraseña eliminada. Guarda para escribir el espacio sin cifrar.","Mot de passe supprimé. Enregistrez pour écrire l’espace non chiffré.","Passwort entfernt. Speichere, um den Space unverschlüsselt zu schreiben.","Password rimossa. Salva per scrivere lo spazio non cifrato.","Palavra-passe removida. Guarde para escrever o espaço sem encriptação."],
@@ -387,8 +390,6 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Search this space": ["このスペースを検索","搜索此空间","搜尋此空間","Buscar en este espacio","Rechercher dans cet espace","Diesen Space durchsuchen","Cerca in questo spazio","Pesquisar neste espaço"],
"Set a password…": ["パスワードを設定…","设置密码…","設定密碼…","Establecer una contraseña…","Définir un mot de passe…","Passwort festlegen…","Imposta una password…","Definir uma palavra-passe…"],
"Share this space": ["このスペースを共有","共享此空间","分享此空間","Compartir este espacio","Partager cet espace","Diesen Space teilen","Condividi questo spazio","Partilhar este espaço"],
- "Show as a board": ["ボードで表示","以看板显示","以看板顯示","Mostrar como tablero","Afficher en tableau","Als Board anzeigen","Mostra come bacheca","Mostrar como quadro"],
- "Show as a list": ["リストで表示","以列表显示","以清單顯示","Mostrar como lista","Afficher en liste","Als Liste anzeigen","Mostra come elenco","Mostrar como lista"],
"Show or hide properties": ["プロパティの表示・非表示","显示或隐藏属性","顯示或隱藏屬性","Mostrar u ocultar las propiedades","Afficher ou masquer les propriétés","Eigenschaften ein- oder ausblenden","Mostra o nascondi le proprietà","Mostrar ou ocultar as propriedades"],
"Show or hide the page list": ["ページ一覧の表示・非表示","显示或隐藏页面列表","顯示或隱藏頁面清單","Mostrar u ocultar la lista de páginas","Afficher ou masquer la liste des pages","Seitenliste ein- oder ausblenden","Mostra o nascondi l’elenco delle pagine","Mostrar ou ocultar a lista de páginas"],
"Show playback controls to the reader": ["読み手に再生コントロールを表示する","向读者显示播放控件","向讀者顯示播放控制項","Mostrar los controles de reproducción a quien lee","Afficher les contrôles de lecture au lecteur","Wiedergabesteuerung für Lesende anzeigen","Mostra i controlli di riproduzione a chi legge","Mostrar os controlos de reprodução a quem lê"],
@@ -514,6 +515,7 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"What is in the picture": ["画像に写っているもの","图片里是什么","圖片裡是什麼","Qué hay en la imagen","Ce que montre l’image","Was auf dem Bild zu sehen ist","Che cosa mostra l’immagine","O que está na imagem"],
"What this is": ["これが何か","这是什么","這是什麼","Qué es esto","Ce que c’est","Worum es sich handelt","Di che cosa si tratta","O que é isto"],
"What’s new →": ["新着情報 →","更新内容 →","更新內容 →","Novedades →","Nouveautés →","Neuerungen →","Novità →","Novidades →"],
+ "Which pages": ["どのページ","哪些页面","哪些頁面","Qué páginas","Quelles pages","Welche Seiten","Quali pagine","Que páginas"],
"Wide": ["広め","加宽","加寬","Ancho","Large","Breit","Largo","Largo"],
"Width": ["幅","宽度","寬度","Anchura","Largeur","Breite","Larghezza","Largura"],
"Width %": ["幅 %","宽度 %","寬度 %","Ancho %","Largeur %","Breite %","Larghezza %","Largura %"],
diff --git a/spaces/src/i18n/pt.ts b/spaces/src/i18n/pt.ts
index 7d3a8ea6..8ee3f827 100644
--- a/spaces/src/i18n/pt.ts
+++ b/spaces/src/i18n/pt.ts
@@ -594,4 +594,10 @@ export const pt: Catalog = {
"Added {name}": "{name} adicionada",
"Name": "Nome",
"New property": "Nova propriedade",
+ "Choose which pages this view holds": "Escolhe que páginas esta vista contém",
+ "Every page with a status": "Todas as páginas com estado",
+ "Nested under": "Aninhadas em",
+ "Pages nested under this one": "Páginas aninhadas sob esta",
+ "Pages that have this property": "Páginas que têm esta propriedade",
+ "Which pages": "Que páginas",
}
diff --git a/spaces/src/i18n/zh-Hans.ts b/spaces/src/i18n/zh-Hans.ts
index 0dc84818..7409e77b 100644
--- a/spaces/src/i18n/zh-Hans.ts
+++ b/spaces/src/i18n/zh-Hans.ts
@@ -594,4 +594,10 @@ export const zh_Hans: Catalog = {
"Added {name}": "已添加{name}",
"Name": "名称",
"New property": "新建属性",
+ "Choose which pages this view holds": "选择此视图包含哪些页面",
+ "Every page with a status": "所有带状态的页面",
+ "Nested under": "嵌套于",
+ "Pages nested under this one": "嵌套在此页面下的页面",
+ "Pages that have this property": "具有此属性的页面",
+ "Which pages": "哪些页面",
}
diff --git a/spaces/src/i18n/zh-Hant.ts b/spaces/src/i18n/zh-Hant.ts
index 55b92327..5c71ec51 100644
--- a/spaces/src/i18n/zh-Hant.ts
+++ b/spaces/src/i18n/zh-Hant.ts
@@ -594,4 +594,10 @@ export const zh_Hant: Catalog = {
"Added {name}": "已新增{name}",
"Name": "名稱",
"New property": "新增屬性",
+ "Choose which pages this view holds": "選擇此檢視包含哪些頁面",
+ "Every page with a status": "所有帶狀態的頁面",
+ "Nested under": "巢狀於",
+ "Pages nested under this one": "巢狀在此頁面下的頁面",
+ "Pages that have this property": "具有此屬性的頁面",
+ "Which pages": "哪些頁面",
}
diff --git a/spaces/src/render.ts b/spaces/src/render.ts
index 8ff2077e..a7964694 100644
--- a/spaces/src/render.ts
+++ b/spaces/src/render.ts
@@ -15,7 +15,7 @@ import { tokenize } from './highlight'
import { t, locale } from './i18n'
import { TAG_OF, LIST_OF, SPEC, TONE, mediaPlayback } from './blocks'
import {
- fieldByKey, optionOf, issuesOf, headerLength, propBlockOf,
+ fieldByKey, fieldsOf, optionOf, viewRows, headerLength, propBlockOf,
passesFilter, filterCount, unknownFilterKeys,
sortRows, unknownSortKeys, type ViewSort, type FieldSpec,
} from './fields'
@@ -991,7 +991,7 @@ function renderView(host: HTMLElement, b: Block, doc: SpacesDoc, opts: RenderOpt
const field = fieldByKey(doc, groupKey)
const filter = (b as { filter?: unknown }).filter
const sort = (b as { sort?: unknown }).sort
- const all = issuesOf(doc)
+ const all = viewRows(doc, (b as { source?: unknown }).source)
const rows = sortRows(doc, all.filter((r) => passesFilter(doc, r.values, filter)), sort)
const head = document.createElement('div')
@@ -1023,9 +1023,23 @@ function renderView(host: HTMLElement, b: Block, doc: SpacesDoc, opts: RenderOpt
// so a view block could hold `layout:'list'` that nothing in the app could
// produce or undo. One button, because there are two of them and a menu to
// choose between two things is a menu too many.
- const asList = layout === 'list'
- const layoutB = btn('viewLayout', asList ? t('List') : t('Board'),
- asList ? t('Show as a board') : t('Show as a list'))
+ // THREE shapes now, so the button says what you are looking at and the
+ // click moves to the next one. A menu to choose between three is still a
+ // menu too many; a cycle is one control and one word.
+ const LAYOUT_WORD: Record<string, string> = { board: 'Board', list: 'List', table: 'Table' }
+ const here = LAYOUT_WORD[layout] ? layout : 'board'
+ const asList = here !== 'board'
+ // Three WHOLE sentences rather than one with the shape interpolated into
+ // it. "Show as a {what}" reads fine in English and breaks in half the
+ // catalogs, where the article and the adjective agree with the noun's
+ // gender — der Tafel / die Liste, un tableau / une liste. Two of these
+ // three keys already existed for the same reason.
+ const NEXT_TIP: Record<string, string> = {
+ board: 'Show as a list', list: 'Show as a table', table: 'Show as a board',
+ }
+ const NEXT: Record<string, string> = { board: 'list', list: 'table', table: 'board' }
+ const layoutB = btn('viewLayout', t(LAYOUT_WORD[here]), t(NEXT_TIP[here]))
+ layoutB.dataset.next = NEXT[here]
// GROUP BY. Only fields with declared options: a board's columns ARE the
// option list, so grouping by a free-text field would make one column per
@@ -1049,7 +1063,19 @@ function renderView(host: HTMLElement, b: Block, doc: SpacesDoc, opts: RenderOpt
// a LIST has no columns, so the field the columns would come from is not a
// question it can be asked
- head.append(layoutB, ...(asList ? [] : [groupB]), sortB, openB, filterB)
+ // WHICH PAGES. Named after what it answers rather than "Source", because
+ // the question in the reader's head is "what is in this?" — and it says the
+ // answer, not the word, when there is one.
+ const src = (b as { source?: { has?: unknown; under?: unknown } }).source
+ const hasKey = typeof src?.has === 'string' ? src.has : ''
+ const underId = typeof src?.under === 'string' ? src.under : ''
+ const srcLabel = hasKey ? (fieldByKey(doc, hasKey)?.label ?? hasKey)
+ : underId ? (doc.pages.find((p) => p.id === underId)?.title || t('Untitled'))
+ : t('Issues')
+ const sourceB = btn('viewSource', `${t('Pages')} · ${srcLabel}`,
+ t('Choose which pages this view holds'), !!(hasKey || underId))
+
+ head.append(layoutB, sourceB, ...(asList ? [] : [groupB]), sortB, openB, filterB)
}
host.appendChild(head)
@@ -1142,6 +1168,74 @@ function renderView(host: HTMLElement, b: Block, doc: SpacesDoc, opts: RenderOpt
return a
}
+ // TABLE — the shape a base is usually looked at in, and the one this app did
+ // not have. Columns are the fields the ROWS ACTUALLY CARRY, in the schema's
+ // declared order: a table of books should not carry an Estimate column
+ // because the vocabulary happens to contain one, and a page that has a field
+ // the others lack should not be the reason everyone gets an empty column.
+ if (layout === 'table') {
+ const keys = fieldsOf(doc).map((f) => f.key).filter((k) => rows.some((r) => r.values.has(k)))
+ const wrap = document.createElement('div')
+ // its own scroller: a wide table must not make the PAGE scroll sideways
+ wrap.className = 'sp-view-tablewrap'
+ const table = document.createElement('table')
+ table.className = 'sp-view-table'
+ const thead = document.createElement('thead')
+ const hr = document.createElement('tr')
+ const th0 = document.createElement('th')
+ th0.textContent = t('Page')
+ hr.appendChild(th0)
+ for (const k of keys) {
+ const th = document.createElement('th')
+ th.textContent = fieldByKey(doc, k)?.label ?? k
+ hr.appendChild(th)
+ }
+ thead.appendChild(hr)
+ table.appendChild(thead)
+ const tb = document.createElement('tbody')
+ for (const r of rows) {
+ const tr = document.createElement('tr')
+ const td0 = document.createElement('td')
+ // the page itself, reached the same way a card reaches it
+ const a = document.createElement('a')
+ a.className = 'sp-view-cellink'
+ a.href = `#p/${r.page.id}`
+ a.dataset.page = r.page.id
+ a.textContent = r.page.title || t('Untitled')
+ td0.appendChild(a)
+ tr.appendChild(td0)
+ for (const k of keys) {
+ const td = document.createElement('td')
+ const f = fieldByKey(doc, k)
+ const v = r.values.get(k)
+ // THROUGH THE OPTION, so a select shows its label and its colour rather
+ // than the id the model stores — the same thing propHtml does for the
+ // header strip, and for the same reason: the id is not for reading.
+ const opt = optionOf(f, v)
+ if (opt) {
+ const chip = document.createElement('span')
+ chip.className = 'sp-prop-chip'
+ const dot = document.createElement('span')
+ dot.className = 'sp-prop-dot'
+ if (opt.color) dot.style.background = opt.color
+ chip.append(dot, document.createTextNode(opt.label))
+ td.appendChild(chip)
+ } else if (v !== undefined && v !== null && String(v) !== '') {
+ td.textContent = String(v)
+ } else {
+ td.className = 'sp-view-empty'
+ td.textContent = '—'
+ }
+ tr.appendChild(td)
+ }
+ tb.appendChild(tr)
+ }
+ table.appendChild(tb)
+ wrap.appendChild(table)
+ host.appendChild(wrap)
+ return
+ }
+
if (layout === 'list') {
const ul = document.createElement('ul')
ul.className = 'sp-view-list'
diff --git a/spaces/src/styles.css b/spaces/src/styles.css
index e62d85f6..76aa1255 100644
--- a/spaces/src/styles.css
+++ b/spaces/src/styles.css
@@ -1843,6 +1843,33 @@ button.sp-issue-set:hover { background: var(--chrome-2); border-color: var(--edg
content: ''; display: block; height: 2px; border-radius: 2px;
background: var(--accent); margin: 0 1px;
}
+/* THE TABLE. Rows are pages, so the first column reads as a list of links and
+ the rest as data: tabular figures, a quiet rule under the head, and no
+ vertical lines — a grid of boxes is a spreadsheet, and this is a list of
+ documents that happens to have columns. */
+.sp-view-tablewrap { overflow-x: auto; margin: 0 0 4px; }
+.sp-view-table {
+ border-collapse: collapse; width: 100%; font-size: 13.5px;
+ font-variant-numeric: tabular-nums;
+}
+.sp-view-table th {
+ text-align: start; font-weight: 600; font-size: 12px; color: var(--muted);
+ padding: 4px 12px 7px 0; border-bottom: 1px solid var(--line); white-space: nowrap;
+}
+.sp-view-table td {
+ padding: 7px 12px 7px 0; border-bottom: 1px solid var(--line-2, var(--line));
+ vertical-align: baseline;
+}
+.sp-view-table tr:last-child td { border-bottom: 0; }
+.sp-view-table tr:hover td { background: var(--chrome); }
+/* the page's own column carries the weight; the values are supporting text */
+.sp-view-table td:first-child { font-weight: 500; }
+.sp-view-cellink { color: var(--ink); text-decoration: none; }
+.sp-view-cellink:hover { text-decoration: underline; }
+.sp-view-empty { color: var(--ph, var(--muted)); }
+/* a select's value, the same chip the header strip and the board cards use */
+.sp-prop-chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
+
.sp-view-list { list-style: none; margin: 0; padding: 0; }
.sp-view-list li { margin: 0 0 6px; }