Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

spaces: a page can be a record, and the schema grows by being used (#388)

nyblnetc970be16c164
diff --git a/scripts/test-spaces-model.ts b/scripts/test-spaces-model.ts
index 0fc1b973..ee0c7f4b 100644
--- a/scripts/test-spaces-model.ts
+++ b/scripts/test-spaces-model.ts
@@ -444,6 +444,40 @@ for (const [label, input, err] of [
'no place styles itself as current without saying so — sp-here and aria-current stay paired')
}
+// ---- a page can be a record, and the schema grows by being used ------------
+// `doc.fields` has been a per-document vocabulary since the tracker shipped and
+// NOTHING EVER WROTE IT: the only way to give a page a property was "Make this
+// page an issue", which adds four fields or none. So the schema was
+// configurable in the format and fixed in the app, and a space could hold a
+// backlog but never a reading list.
+//
+// The trap this pins is `fieldsOf`'s fallback. It returns DEFAULT_FIELDS only
+// while `doc.fields` is absent or empty — so a document that has never declared
+// a schema and then gains ONE field would, if that field were pushed into an
+// empty array, lose Status, Priority, Assignee and Estimate in the same stroke.
+// Every issue would keep its `prop` blocks, and the board grouping them by
+// status would have no status field to group by.
+{
+ const fs = await import('node:fs')
+ const fields = fs.readFileSync(new URL('../spaces/src/fields.ts', import.meta.url), 'utf8')
+ const ed = fs.readFileSync(new URL('../spaces/src/editor.ts', import.meta.url), 'utf8')
+ const props = fs.readFileSync(new URL('../spaces/src/props.ts', import.meta.url), 'utf8')
+
+ ok(/export function withField\(/.test(fields), 'there is one way to add a field to the vocabulary')
+ // The seeding is the whole point: it must start from fieldsOf(doc), never
+ // from doc.fields directly.
+ ok(/const current = fieldsOf\(doc\)/.test(fields),
+ '…and it seeds from the DEFAULTS, so the first custom field does not erase them')
+ ok(/export function freeFieldKey\(/.test(fields),
+ 'a new field gets a key that is free — keys outlive labels and views group by them')
+
+ ok(/openAddProperty\(pageId: string, anchor: HTMLElement\)/.test(ed), 'a page can be given a property')
+ ok(/withField\(s\.doc, spec\)/.test(ed), '…and naming a new one writes it into the document vocabulary')
+ ok(/splice\(headerLength\(p\), 0, propBlock\(/.test(ed),
+ '…as a prop block in the header strip, where the readable form is written with it')
+ ok(/openAddProperty\(page\.id, addProp\)/.test(props), 'the properties panel offers it')
+}
+
// ---- 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 396b1741..60e94ecd 100644
--- a/spaces/src/editor.ts
+++ b/spaces/src/editor.ts
@@ -25,7 +25,7 @@ import type { MarkTag } from './marks'
import { MENU_SPECS, MD_SPECS, SPEC, CALLOUT_TONES } from './blocks'
import {
fieldByKey, fieldsOf, propHtml, propBlock, propBlockOf, isIssue, headerLength,
- reorderPages, columnMoves, ISSUE_FIELDS,
+ reorderPages, columnMoves, ISSUE_FIELDS, withField, freeFieldKey, FIELD_TYPE_LABEL,
type DropAim, type FieldSpec, type ViewFilter, type ViewSort,
} from './fields'
import { planImport, type SourceFile } from './markdown'
@@ -214,6 +214,7 @@ export class Editor {
pickPoster: (id) => void this.pickPoster(id),
pickMedia: (id) => void this.pickMedia(id),
openIconPicker: (pageId, anchor) => this.openIconPicker(pageId, anchor),
+ openAddProperty: (pageId, anchor) => this.openAddProperty(pageId, anchor),
pageIcon: (icon) => pageIcon(icon),
openLinkCard: (id) => this.openLinkCard(id),
addTableRow: (id, at) => this.addTableRow(id, at),
@@ -3270,6 +3271,84 @@ export class Editor {
this.overlayReflow = () => removeEventListener('resize', reflow)
}
+ /**
+ * Put a property on this page — and define it, if it does not exist yet.
+ *
+ * THE SCHEMA IS EDITED WHERE IT IS USED. `doc.fields` has been a per-document
+ * vocabulary since the tracker shipped, and nothing has ever written it: the
+ * only way to give a page a property was "Make this page an issue", which
+ * adds Status, Priority, Assignee and Estimate together or not at all. So the
+ * schema was configurable in the format and fixed in the app.
+ *
+ * A separate schema editor would have been the obvious fix and the wrong one.
+ * DEFAULT_FIELDS says it in its own comment — "a tracker you have to design
+ * before you can use it is the thing everybody hates about the alternatives"
+ * — so a property is created in passing, at the moment somebody wants one,
+ * and the vocabulary grows as a side effect of use. That is what lets one
+ * space hold a reading list, a film log and a backlog at once: the fields are
+ * a flat vocabulary and each page carries only the ones it uses.
+ */
+ openAddProperty(pageId: string, anchor: HTMLElement): void {
+ const s = this.store
+ if (s.readOnly) return
+ const page = s.index.page.get(pageId)
+ if (!page) return
+
+ this.popover(anchor, (pop) => {
+ const has = new Set(page.blocks
+ .filter((b) => b.type === 'prop')
+ .map((b) => String((b as { key?: unknown }).key ?? '')))
+
+ const put = (f: FieldSpec, fields?: FieldSpec[]) => {
+ s.commit(() => {
+ if (fields) (s.doc as { fields?: FieldSpec[] }).fields = fields
+ const p = s.index.page.get(pageId)
+ if (!p) return
+ p.blocks.splice(headerLength(p), 0, propBlock(f, f.def ?? '', newBlock('prop').id))
+ })
+ this.closeOverlay()
+ this.repaint()
+ this.status(t('Added {name}', { name: f.label }))
+ }
+
+ const spare = fieldsOf(s.doc).filter((f) => !has.has(f.key))
+ if (spare.length) {
+ pop.append(el('div', 'sp-pop-title', t('Add a property')))
+ for (const f of spare) {
+ pop.append(this.menuItem('tag', f.label, t(FIELD_TYPE_LABEL[f.vt] ?? 'Text'), () => put(f)))
+ }
+ }
+
+ pop.append(el('div', 'sp-pop-title', t('New property')))
+ const form = el('div', 'sp-newprop')
+ const name = document.createElement('input')
+ name.type = 'text'
+ name.className = 'sp-input'
+ name.placeholder = t('Name')
+ const type = document.createElement('select')
+ type.className = 'sp-select'
+ for (const [vt, label] of Object.entries(FIELD_TYPE_LABEL)) {
+ const o = document.createElement('option')
+ o.value = vt
+ o.textContent = t(label)
+ type.append(o)
+ }
+ type.value = 'text'
+ const add = el('button', 'sp-btn sp-primary', t('Add'))
+ const submit = () => {
+ const label = name.value.trim()
+ if (!label) { name.focus(); return }
+ const spec: FieldSpec = { key: freeFieldKey(s.doc, label), label, vt: type.value as FieldSpec['vt'] }
+ put(spec, withField(s.doc, spec))
+ }
+ add.addEventListener('click', submit)
+ name.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); submit() } })
+ form.append(name, type, add)
+ pop.append(form)
+ afterPaint(() => name.focus())
+ })
+ }
+
private closeOverlay(): void {
this.overlayReflow?.()
this.overlayReflow = null
diff --git a/spaces/src/fields.ts b/spaces/src/fields.ts
index fd85918c..63601c76 100644
--- a/spaces/src/fields.ts
+++ b/spaces/src/fields.ts
@@ -31,6 +31,20 @@ import type { SpacesDoc, Page, Block } from './model'
* permanent commitment, and a tracker needs exactly these. */
export type FieldType = 'select' | 'person' | 'number' | 'date' | 'text' | 'labels'
+/**
+ * What each type is called to somebody choosing one. Keys are the model's
+ * words and never translated; the labels are English source strings that t()
+ * looks up at render time — never here, where they would freeze at import.
+ */
+export const FIELD_TYPE_LABEL: Record<FieldType, string> = {
+ text: 'Text',
+ select: 'Select',
+ number: 'Number',
+ date: 'Date',
+ person: 'Person',
+ labels: 'Labels',
+}
+
export interface FieldOption {
id: string
label: string
@@ -418,6 +432,44 @@ export const propBlockOf = (page: Page, key: string): Block | undefined =>
page.blocks.find((b) => b.type === 'prop' && (b as { key?: unknown }).key === key)
/** Build a prop block, with its readable form already in step. */
+/**
+ * The document's field vocabulary with one more field in it.
+ *
+ * SEEDS FROM THE DEFAULTS ON FIRST WRITE, and that is the whole reason this is
+ * a function rather than a push. `fieldsOf` falls back to DEFAULT_FIELDS only
+ * while `doc.fields` is absent or empty — so a document that has never declared
+ * a schema and then gains ONE field would, if the field were simply pushed into
+ * an empty array, lose Status, Priority, Assignee and Estimate in the same
+ * stroke. Every issue in the space would keep its `prop` blocks (they carry
+ * their own readable html) but the board grouping them by status would have no
+ * status field to group by.
+ *
+ * So the first custom field writes the defaults down beside itself, which is
+ * also the honest thing: once you have edited the schema it stops being
+ * implicit.
+ */
+export function withField(doc: SpacesDoc, spec: FieldSpec): FieldSpec[] {
+ const current = fieldsOf(doc)
+ if (current.some((f) => f.key === spec.key)) {
+ return current.map((f) => (f.key === spec.key ? spec : f))
+ }
+ return [...current, spec]
+}
+
+/**
+ * A key for a field somebody just named.
+ *
+ * Keys are what `prop` blocks store and what views group by, so they outlive
+ * every rename of the label and must never collide. Derived from the label,
+ * then suffixed until it is free.
+ */
+export function freeFieldKey(doc: SpacesDoc, label: string): string {
+ const base = label.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'field'
+ const taken = new Set(fieldsOf(doc).map((f) => f.key))
+ if (!taken.has(base)) return base
+ for (let n = 2; ; n++) if (!taken.has(`${base}-${n}`)) return `${base}-${n}`
+}
+
export function propBlock(f: FieldSpec, value: unknown, id: string): Block {
return { id, type: 'prop', key: f.key, value, html: propHtml(f, value) } as Block
}
diff --git a/spaces/src/i18n/de.ts b/spaces/src/i18n/de.ts
index 61366118..2fe19dbe 100644
--- a/spaces/src/i18n/de.ts
+++ b/spaces/src/i18n/de.ts
@@ -588,4 +588,10 @@ export const de: Catalog = {
"This list": "Diese Liste",
"Undo, redo": "Rückgängig, wiederherstellen",
"Writing": "Schreiben",
+ "Add": "Hinzufügen",
+ "Add a property": "Eine Eigenschaft hinzufügen",
+ "Add property…": "Eigenschaft hinzufügen…",
+ "Added {name}": "{name} hinzugefügt",
+ "Name": "Name",
+ "New property": "Neue Eigenschaft",
}
diff --git a/spaces/src/i18n/es.ts b/spaces/src/i18n/es.ts
index 1ee65b8a..5f248b0f 100644
--- a/spaces/src/i18n/es.ts
+++ b/spaces/src/i18n/es.ts
@@ -588,4 +588,10 @@ export const es: Catalog = {
"This list": "Esta lista",
"Undo, redo": "Deshacer, rehacer",
"Writing": "Escribir",
+ "Add": "Añadir",
+ "Add a property": "Añadir una propiedad",
+ "Add property…": "Añadir propiedad…",
+ "Added {name}": "Se añadió {name}",
+ "Name": "Nombre",
+ "New property": "Nueva propiedad",
}
diff --git a/spaces/src/i18n/fr.ts b/spaces/src/i18n/fr.ts
index b09bf05f..431caaaf 100644
--- a/spaces/src/i18n/fr.ts
+++ b/spaces/src/i18n/fr.ts
@@ -588,4 +588,10 @@ export const fr: Catalog = {
"This list": "Cette liste",
"Undo, redo": "Annuler, rétablir",
"Writing": "Écrire",
+ "Add": "Ajouter",
+ "Add a property": "Ajouter une propriété",
+ "Add property…": "Ajouter une propriété…",
+ "Added {name}": "{name} ajoutée",
+ "Name": "Nom",
+ "New property": "Nouvelle propriété",
}
diff --git a/spaces/src/i18n/it.ts b/spaces/src/i18n/it.ts
index 65149c8e..cd97b205 100644
--- a/spaces/src/i18n/it.ts
+++ b/spaces/src/i18n/it.ts
@@ -588,4 +588,10 @@ export const it: Catalog = {
"This list": "Questo elenco",
"Undo, redo": "Annulla, ripeti",
"Writing": "Scrivere",
+ "Add": "Aggiungi",
+ "Add a property": "Aggiungi una proprietà",
+ "Add property…": "Aggiungi proprietà…",
+ "Added {name}": "{name} aggiunta",
+ "Name": "Nome",
+ "New property": "Nuova proprietà",
}
diff --git a/spaces/src/i18n/ja.ts b/spaces/src/i18n/ja.ts
index 973373e0..d2668746 100644
--- a/spaces/src/i18n/ja.ts
+++ b/spaces/src/i18n/ja.ts
@@ -588,4 +588,10 @@ export const ja: Catalog = {
"This list": "この一覧",
"Undo, redo": "取り消し・やり直し",
"Writing": "書く",
+ "Add": "追加",
+ "Add a property": "プロパティを追加",
+ "Add property…": "プロパティを追加…",
+ "Added {name}": "{name} を追加しました",
+ "Name": "名前",
+ "New property": "新しいプロパティ",
}
diff --git a/spaces/src/i18n/packed.ts b/spaces/src/i18n/packed.ts
index bacc4ebb..70d06478 100644
--- a/spaces/src/i18n/packed.ts
+++ b/spaces/src/i18n/packed.ts
@@ -32,13 +32,17 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"A typed value on this page": ["このページの型付きの値","此页面上的类型化值","此頁面上的型別值","Un valor con tipo en esta página","Une valeur typée sur cette page","Ein typisierter Wert auf dieser Seite","Un valore tipizzato su questa pagina","Um valor tipado nesta página"],
"About this space": ["このスペースについて","关于此空间","關於此空間","Acerca de este espacio","À propos de cet espace","Über diesen Space","Informazioni su questo spazio","Sobre este espaço"],
"Access reset — only copies saved from now on can join": ["アクセスをリセットしました — 今後保存したコピーだけが参加できます","访问已重置 — 只有此后保存的副本才能加入","存取已重設 — 只有此後儲存的副本才能加入","Acceso restablecido — solo las copias guardadas a partir de ahora podrán unirse","Accès réinitialisé — seules les copies enregistrées désormais pourront rejoindre","Zugriff zurückgesetzt — nur ab jetzt gespeicherte Kopien können beitreten","Accesso reimpostato — solo le copie salvate d’ora in poi potranno unirsi","Acesso redefinido — apenas cópias salvas de agora em diante podem entrar"],
+ "Add": ["追加","添加","新增","Añadir","Ajouter","Hinzufügen","Aggiungi","Adicionar"],
"Add a block below": ["下にブロックを追加","在下方添加块","在下方新增區塊","Añadir un bloque debajo","Ajouter un bloc en dessous","Block darunter hinzufügen","Aggiungi un blocco sotto","Adicionar um bloco abaixo"],
"Add a column after": ["右に列を追加","在右侧添加一列","在右側新增一欄","Añadir una columna después","Ajouter une colonne après","Spalte danach einfügen","Aggiungi una colonna dopo","Adicionar uma coluna depois"],
"Add a link": ["リンクを追加","添加链接","新增連結","Añadir un enlace","Ajouter un lien","Link hinzufügen","Aggiungi un collegamento","Adicionar um link"],
"Add a picture": ["画像を追加","添加图片","新增圖片","Añadir una imagen","Ajouter une image","Bild hinzufügen","Aggiungi un'immagine","Adicionar uma imagem"],
+ "Add a property": ["プロパティを追加","添加属性","新增屬性","Añadir una propiedad","Ajouter une propriété","Eine Eigenschaft hinzufügen","Aggiungi una proprietà","Adicionar uma propriedade"],
"Add a row below": ["下に行を追加","在下方添加一行","在下方新增一列","Añadir una fila debajo","Ajouter une ligne en dessous","Zeile darunter einfügen","Aggiungi una riga sotto","Adicionar uma linha abaixo"],
"Add below": ["下に追加","在下方添加","在下方新增","Añadir debajo","Ajouter en dessous","Darunter einfügen","Aggiungi sotto","Adicionar abaixo"],
"Add pages under": ["ページを追加する場所","将页面添加到","將頁面加入到","Añadir las páginas debajo de","Ajouter les pages sous","Seiten einfügen unter","Aggiungi le pagine sotto","Adicionar as páginas por baixo de"],
+ "Add property…": ["プロパティを追加…","添加属性…","新增屬性…","Añadir propiedad…","Ajouter une propriété…","Eigenschaft hinzufügen…","Aggiungi proprietà…","Adicionar propriedade…"],
+ "Added {name}": ["{name} を追加しました","已添加{name}","已新增{name}","Se añadió {name}","{name} ajoutée","{name} hinzugefügt","{name} aggiunta","{name} adicionada"],
"Address of a video or audio file": ["動画または音声ファイルのアドレス","视频或音频文件的地址","影片或音訊檔案的位址","Dirección de un archivo de vídeo o audio","Adresse d’un fichier vidéo ou audio","Adresse einer Video- oder Audiodatei","Indirizzo di un file video o audio","Endereço de um ficheiro de vídeo ou áudio"],
"Adds status, priority, assignee, estimate": ["ステータス・優先度・担当者・見積もりを追加します","添加状态、优先级、负责人和估算","新增狀態、優先順序、負責人與估算","Añade estado, prioridad, responsable y estimación","Ajoute statut, priorité, responsable et estimation","Fügt Status, Priorität, Bearbeiter:in und Schätzung hinzu","Aggiunge stato, priorità, assegnatario e stima","Adiciona estado, prioridade, responsável e estimativa"],
"All text. Nothing is embedded, so this file is as small as a space gets.": ["すべてテキストです。埋め込みはないので、このファイルはスペースとして最小の大きさです。","全是文字。没有嵌入任何内容,所以这个文件已是空间能达到的最小体积。","全是文字。沒有嵌入任何內容,所以這個檔案已是空間能達到的最小體積。","Todo es texto. No hay nada incrustado, así que este archivo es lo más pequeño que puede ser un espacio.","Que du texte. Rien n’est intégré, donc ce fichier est aussi léger qu’un espace peut l’être.","Nur Text. Nichts ist eingebettet, also ist diese Datei so klein, wie ein Space nur sein kann.","Solo testo. Non c’è nulla di incorporato, quindi questo file è il più piccolo possibile per uno spazio.","Só texto. Nada está incorporado, por isso este ficheiro é o mais pequeno que um espaço pode ser."],
@@ -255,10 +259,12 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Move down": ["下へ移動","下移","下移","Bajar","Descendre","Nach unten","Sposta giù","Mover para baixo"],
"Move up": ["上へ移動","上移","上移","Subir","Monter","Nach oben","Sposta su","Mover para cima"],
"Muted": ["ミュート","静音","靜音","Silenciado","Muet","Stumm","Muto","Sem som"],
+ "Name": ["名前","名称","名稱","Nombre","Nom","Name","Nome","Nome"],
"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)"],
"New page inside": ["この中に新規ページ","在其中新建页面","在其中新增頁面","Nueva página dentro","Nouvelle page à l’intérieur","Neue Unterseite","Nuova pagina interna","Nova página dentro desta"],
+ "New property": ["新しいプロパティ","新建属性","新增屬性","Nueva propiedad","Nouvelle propriété","Neue Eigenschaft","Nuova proprietà","Nova propriedade"],
"New to Bento? Find templates, the gallery and the AI editing guide at {home} — or ⭐ it on {gh}.": ["Bento は初めてですか?テンプレート、ギャラリー、AI編集ガイドは {home} でどうぞ — {gh} で ⭐ もぜひ。","第一次用 Bento?在 {home} 查看模板、图库和 AI 编辑指南 — 也欢迎到 {gh} 点 ⭐。","第一次用 Bento?在 {home} 查看範本、圖庫和 AI 編輯指南 — 也歡迎到 {gh} 按 ⭐。","¿Nuevo en Bento? Encuentra plantillas, la galería y la guía de edición con IA en {home} — o dale ⭐ en {gh}.","Nouveau sur Bento ? Trouvez des modèles, la galerie et le guide d’édition par IA sur {home} — ou mettez une ⭐ sur {gh}.","Neu bei Bento? Vorlagen, die Galerie und den KI-Bearbeitungsleitfaden findest du auf {home} — oder gib ⭐ auf {gh}.","Nuovo su Bento? Trovi modelli, la galleria e la guida all’editing con IA su {home} — o metti una ⭐ su {gh}.","Novo no Bento? Encontre modelos, a galeria e o guia de edição com IA em {home} — ou dê uma ⭐ no {gh}."],
"Next (⏎)": ["次へ (⏎)","下一个 (⏎)","下一個 (⏎)","Siguiente (⏎)","Suivant (⏎)","Weiter (⏎)","Successivo (⏎)","Seguinte (⏎)"],
"No Markdown files in that selection": ["選択に Markdown ファイルがありません","所选内容里没有 Markdown 文件","所選項目中沒有 Markdown 檔案","No hay archivos Markdown en esa selección","Aucun fichier Markdown dans cette sélection","Keine Markdown-Dateien in dieser Auswahl","Nessun file Markdown in questa selezione","Não há ficheiros Markdown nessa seleção"],
diff --git a/spaces/src/i18n/pt.ts b/spaces/src/i18n/pt.ts
index 8bac1a3c..7d3a8ea6 100644
--- a/spaces/src/i18n/pt.ts
+++ b/spaces/src/i18n/pt.ts
@@ -588,4 +588,10 @@ export const pt: Catalog = {
"This list": "Esta lista",
"Undo, redo": "Anular, refazer",
"Writing": "Escrever",
+ "Add": "Adicionar",
+ "Add a property": "Adicionar uma propriedade",
+ "Add property…": "Adicionar propriedade…",
+ "Added {name}": "{name} adicionada",
+ "Name": "Nome",
+ "New property": "Nova propriedade",
}
diff --git a/spaces/src/i18n/zh-Hans.ts b/spaces/src/i18n/zh-Hans.ts
index a44b9812..0dc84818 100644
--- a/spaces/src/i18n/zh-Hans.ts
+++ b/spaces/src/i18n/zh-Hans.ts
@@ -588,4 +588,10 @@ export const zh_Hans: Catalog = {
"This list": "本列表",
"Undo, redo": "撤销、重做",
"Writing": "写作",
+ "Add": "添加",
+ "Add a property": "添加属性",
+ "Add property…": "添加属性…",
+ "Added {name}": "已添加{name}",
+ "Name": "名称",
+ "New property": "新建属性",
}
diff --git a/spaces/src/i18n/zh-Hant.ts b/spaces/src/i18n/zh-Hant.ts
index ea8006e4..55b92327 100644
--- a/spaces/src/i18n/zh-Hant.ts
+++ b/spaces/src/i18n/zh-Hant.ts
@@ -588,4 +588,10 @@ export const zh_Hant: Catalog = {
"This list": "本清單",
"Undo, redo": "復原、重做",
"Writing": "書寫",
+ "Add": "新增",
+ "Add a property": "新增屬性",
+ "Add property…": "新增屬性…",
+ "Added {name}": "已新增{name}",
+ "Name": "名稱",
+ "New property": "新增屬性",
}
diff --git a/spaces/src/props.ts b/spaces/src/props.ts
index 2427840e..70f603de 100644
--- a/spaces/src/props.ts
+++ b/spaces/src/props.ts
@@ -48,6 +48,8 @@ export interface PropsHost {
pickPoster(id: string): void
pickMedia(id: string): void
openIconPicker(pageId: string, anchor: HTMLElement): void
+ /** the editor owns popovers; the panel only says which page wants one */
+ openAddProperty(pageId: string, anchor: HTMLElement): void
/** the editor owns the icon set and the emoji fallback */
pageIcon(icon: string | undefined): string
openLinkCard(id: string): void
@@ -329,6 +331,17 @@ export class PropsPanel {
this.row(t('Journal date'), mk('span', 'sp-mono', page.journal))
}
+ // A PAGE IS A RECORD when it wants to be. The properties themselves live in
+ // the page's header strip, where they are read and edited; this is the way
+ // to give the page one it does not have yet — the only route before was
+ // "Make this page an issue", which is four fields or nothing.
+ if (!this.app.locked()) {
+ const addProp = mk('button', 'sp-btn', t('Add property…'))
+ addProp.type = 'button'
+ addProp.addEventListener('click', () => this.app.openAddProperty(page.id, addProp))
+ this.row(t('Properties'), addProp)
+ }
+
// WHAT IS ACTUALLY IN THIS PAGE. Derived at render, never stored: a count
// written into the file is a count that goes stale in somebody's copy.
const words = page.blocks.reduce(
diff --git a/spaces/src/styles.css b/spaces/src/styles.css
index f9fb4a33..e62d85f6 100644
--- a/spaces/src/styles.css
+++ b/spaces/src/styles.css
@@ -1343,6 +1343,13 @@ button.sp-callout-chip:hover { text-decoration: underline; text-underline-offset
.sp-ab-vdo { margin-inline-start: auto; color: var(--muted); }
.sp-ab-version:hover .sp-ab-vdo, .sp-ab-version:focus-visible .sp-ab-vdo { color: var(--blue); }
+/* The new-property form inside the add-property popover: a name, a type and a
+ button, on one line until the popover is too narrow for it. */
+.sp-newprop { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px 6px; }
+.sp-newprop .sp-input { flex: 1 1 120px; min-width: 0; }
+.sp-newprop .sp-select { flex: 0 1 auto; }
+.sp-newprop .sp-btn { flex: 0 0 auto; }
+
/* The shortcut list. Two columns, keys right-aligned against their meanings,
so the eye runs down one edge instead of hunting across a ragged gap. */
/* wider than the other cards, because this one is a two-column table and