domma-cms 1.30.0 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/CLAUDE.md +17 -0
- package/admin/js/api.js +1 -1
- package/admin/js/lib/blocks-arrange.js +1 -1
- package/admin/js/lib/collection-editor-arrange.js +1 -1
- package/admin/js/lib/collection-entries-arrange.js +1 -1
- package/admin/js/lib/collections-arrange.js +1 -1
- package/admin/js/lib/list-tags-arrange.js +1 -1
- package/admin/js/lib/list-tags.js +9 -7
- package/admin/js/lib/pages-arrange.js +1 -1
- package/admin/js/templates/blocks.html +5 -3
- package/admin/js/templates/collections.html +12 -2
- package/admin/js/templates/pages.html +5 -3
- package/admin/js/views/blocks.js +5 -4
- package/admin/js/views/collection-editor.js +10 -4
- package/admin/js/views/collection-entries.js +2 -2
- package/admin/js/views/collections.js +6 -5
- package/admin/js/views/page-editor.js +1 -1
- package/admin/js/views/pages.js +4 -4
- package/docs/DommaFeatures.md +75 -3
- package/docs/api-reference.md +8 -6
- package/package.json +1 -1
- package/plugins/_lib/admin/mail/body-menu.js +1 -1
- package/plugins/_lib/admin/mail/cms-host.js +1 -1
- package/plugins/_lib/admin/mail/compose-window.js +1 -1
- package/plugins/_lib/admin/mail/contacts.js +1 -1
- package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
- package/plugins/_lib/admin/mail/drag-drop.js +1 -1
- package/plugins/_lib/admin/mail/folder-tree.js +1 -1
- package/plugins/_lib/admin/mail/font-controls.js +1 -1
- package/plugins/_lib/admin/mail/fonts.js +1 -1
- package/plugins/_lib/admin/mail/host-context.js +1 -1
- package/plugins/_lib/admin/mail/identity.js +1 -1
- package/plugins/_lib/admin/mail/image-senders-section.js +1 -1
- package/plugins/_lib/admin/mail/keyboard.js +1 -1
- package/plugins/_lib/admin/mail/mail.html +1 -1
- package/plugins/_lib/admin/mail/message-actions.js +1 -1
- package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
- package/plugins/_lib/admin/mail/panes.js +1 -1
- package/plugins/_lib/admin/mail/reader-kit.js +1 -1
- package/plugins/_lib/admin/mail/reader-runtime.js +1 -1
- package/plugins/_lib/admin/mail/reader-view.js +1 -1
- package/plugins/_lib/admin/mail/resizable.js +1 -1
- package/plugins/_lib/admin/mail/restore-spam.js +1 -1
- package/plugins/_lib/admin/mail/rules.js +2 -2
- package/plugins/_lib/admin/mail/scheduling.js +1 -1
- package/plugins/_lib/admin/mail/section-kit.js +1 -1
- package/plugins/_lib/admin/mail/security-note.js +1 -1
- package/plugins/_lib/admin/mail/settings-section.js +1 -1
- package/plugins/_lib/admin/mail/templates.js +1 -1
- package/plugins/_lib/admin/mail/threads.js +1 -1
- package/plugins/_lib/admin/mail/vacation.js +1 -1
- package/plugins/_lib/admin/mail/when-closed.js +1 -1
- package/plugins/_lib/admin/ui/dates.js +1 -1
- package/plugins/_lib/admin/ui/resizable.js +1 -1
- package/plugins/_lib/domma-mail.lock.json +80 -80
- package/plugins/_lib/mail/accountFileStore.js +1 -1
- package/plugins/_lib/mail/accountRepository.js +1 -1
- package/plugins/_lib/mail/accountRoutes.js +1 -1
- package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
- package/plugins/_lib/mail/bodyTokens.js +1 -1
- package/plugins/_lib/mail/compose.js +1 -1
- package/plugins/_lib/mail/defaults.js +1 -1
- package/plugins/_lib/mail/envelope.js +1 -1
- package/plugins/_lib/mail/folderActions.js +1 -1
- package/plugins/_lib/mail/folderRuntime.js +1 -1
- package/plugins/_lib/mail/folders.js +1 -1
- package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
- package/plugins/_lib/mail/mbox.js +1 -1
- package/plugins/_lib/mail/message-action.js +1 -1
- package/plugins/_lib/mail/messageSecurity.js +1 -1
- package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
- package/plugins/_lib/mail/networkAddresses.js +1 -1
- package/plugins/_lib/mail/networkPolicy.js +1 -1
- package/plugins/_lib/mail/oauthAccounts.js +1 -1
- package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
- package/plugins/_lib/mail/oauthRuntime.js +1 -1
- package/plugins/_lib/mail/pollSchedule.js +1 -1
- package/plugins/_lib/mail/poller.js +1 -1
- package/plugins/_lib/mail/pollerRuntime.js +1 -1
- package/plugins/_lib/mail/priority.js +1 -1
- package/plugins/_lib/mail/publicMailbox.js +1 -1
- package/plugins/_lib/mail/readRuntime.js +1 -1
- package/plugins/_lib/mail/render.js +1 -1
- package/plugins/_lib/mail/ruleRunner.js +1 -1
- package/plugins/_lib/mail/schedulerRuntime.js +1 -1
- package/plugins/_lib/mail/secretProvider.js +1 -1
- package/plugins/_lib/mail/secretbox.js +1 -1
- package/plugins/_lib/mail/senderAuth.js +1 -1
- package/plugins/_lib/mail/sieve.js +1 -1
- package/plugins/_lib/mail/smtpService.js +1 -1
- package/plugins/_lib/mail/snoozeRuntime.js +1 -1
- package/plugins/_lib/mail/store.js +1 -1
- package/plugins/_lib/mail/subscriptions.js +1 -1
- package/plugins/_lib/mail/syncPlan.js +1 -1
- package/plugins/_lib/mail/syncRuntime.js +1 -1
- package/plugins/_lib/mail/syncSelection.js +1 -1
- package/plugins/_lib/mail/unreadBadge.js +1 -1
- package/plugins/_lib/mail/unsubscribe.js +1 -1
- package/plugins/_lib/mail/vacationRuntime.js +1 -1
- package/plugins/_lib/mail/write.js +1 -1
- package/public/css/site.css +1 -1
- package/public/js/collection-browser.js +1 -1
- package/server/routes/api/blocks.js +12 -1
- package/server/routes/api/collections.js +9 -1
- package/server/routes/api/list-tags.js +35 -10
- package/server/routes/api/pages.js +16 -2
- package/server/services/collections.js +6 -0
- package/server/services/listTags.js +243 -47
- package/server/services/markdown.js +4 -0
- package/server/templates/page.html +2 -2
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* List tags - admin-only labels that link pages
|
|
3
|
-
*
|
|
2
|
+
* List tags - admin-only labels that link pages, blocks or collections
|
|
3
|
+
* together so their lists can be narrowed to one tag. Nothing on the public
|
|
4
4
|
* site reads them.
|
|
5
5
|
*
|
|
6
|
-
* An item may carry several.
|
|
7
|
-
* frontmatter `adminTags`, a block's sidecar `meta.adminTags`. A page's
|
|
8
|
-
* `tags` are a different thing - editorial, public (search, the Content
|
|
9
|
-
* and are never touched here.
|
|
6
|
+
* An item may carry several. Pages and blocks keep them on the item itself: a
|
|
7
|
+
* page's frontmatter `adminTags`, a block's sidecar `meta.adminTags`. A page's
|
|
8
|
+
* own `tags` are a different thing - editorial, public (search, the Content
|
|
9
|
+
* API) - and are never touched here. Collections keep theirs in
|
|
10
|
+
* config/list-tags.json (`collectionTags: {slug: [tags]}`), NOT in schema.json:
|
|
11
|
+
* seedAll() rewrites preset schemas on every boot and system collections are
|
|
12
|
+
* fixed. A stale entry for a collection that is gone is ignored, and deleting
|
|
13
|
+
* a collection drops its entry (dropCollectionTags).
|
|
10
14
|
*
|
|
11
|
-
* config/list-tags.json keeps the names per kind (`{pages: [], blocks: []
|
|
12
|
-
* so a tag can exist before anything wears it; a tag found
|
|
13
|
-
* in the file is still listed. Absence of the file = no
|
|
15
|
+
* config/list-tags.json keeps the names per kind (`{pages: [], blocks: [],
|
|
16
|
+
* collections: []}`) so a tag can exist before anything wears it; a tag found
|
|
17
|
+
* on an item but not in the file is still listed. Absence of the file = no
|
|
18
|
+
* names yet.
|
|
19
|
+
*
|
|
20
|
+
* Tool tags: every item a Tool owns wears that Tool's display name as a tag,
|
|
21
|
+
* derived on each read and never stored - a collection's `plugin` (or, for the
|
|
22
|
+
* built-in Tools' preset collections, PRESET_TOOL_COLLECTIONS), a block's
|
|
23
|
+
* `meta.plugin`, a page's frontmatter `plugin`. They list with `tool: true`;
|
|
24
|
+
* nobody can add, rename or delete one, and a manual tag may not take a Tool
|
|
25
|
+
* tag's name.
|
|
14
26
|
*
|
|
15
27
|
* Tagging is metadata, not an edit: a page's tags are written without a
|
|
16
28
|
* revision and without moving its updatedAt.
|
|
@@ -18,11 +30,24 @@
|
|
|
18
30
|
import {getConfig, saveConfig} from '../config.js';
|
|
19
31
|
import {getPage, listPages, setPageFrontmatter} from './content.js';
|
|
20
32
|
import {getBlock, listBlocks, setBlockMeta} from './blocks.js';
|
|
33
|
+
import {getCollection, listCollections} from './collections.js';
|
|
34
|
+
import {CORE_TOOLS} from './tools.js';
|
|
21
35
|
|
|
22
|
-
export const KINDS = ['pages', 'blocks'];
|
|
36
|
+
export const KINDS = ['pages', 'blocks', 'collections'];
|
|
23
37
|
export const MAX_TAG = 40;
|
|
24
38
|
const CONFIG_NAME = 'list-tags';
|
|
25
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The built-in Tools' preset collections, which carry no `plugin` of their own.
|
|
42
|
+
* Mirrored in admin/js/lib/list-tags-arrange.js (the admin cannot import server code).
|
|
43
|
+
*/
|
|
44
|
+
export const PRESET_TOOL_COLLECTIONS = Object.freeze({
|
|
45
|
+
'notes-notes': 'notes',
|
|
46
|
+
'todo-items': 'todo',
|
|
47
|
+
'contacts-contacts': 'contacts',
|
|
48
|
+
'contacts-groups': 'contacts'
|
|
49
|
+
});
|
|
50
|
+
|
|
26
51
|
/** One tag name as stored: trimmed, inner whitespace collapsed, capped. '' when unusable. */
|
|
27
52
|
export function normaliseTag(name) {
|
|
28
53
|
if (typeof name !== 'string') return '';
|
|
@@ -53,99 +78,252 @@ function assertKind(kind) {
|
|
|
53
78
|
throw err;
|
|
54
79
|
}
|
|
55
80
|
|
|
81
|
+
function badTag(message) {
|
|
82
|
+
const err = new Error(message);
|
|
83
|
+
err.code = 'BAD_TAG';
|
|
84
|
+
return err;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
88
|
+
|
|
89
|
+
/** The collection tag map, cleaned: slug-shaped keys only, no empty lists. */
|
|
90
|
+
function cleanTagMap(map) {
|
|
91
|
+
const out = {};
|
|
92
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) return out;
|
|
93
|
+
for (const [slug, list] of Object.entries(map)) {
|
|
94
|
+
if (UNSAFE_KEYS.has(slug) || !/^[a-z0-9][a-z0-9_-]*$/i.test(slug)) continue;
|
|
95
|
+
const clean = cleanTagList(list);
|
|
96
|
+
if (clean.length) out[slug] = clean;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
56
101
|
function readRegistry() {
|
|
57
102
|
let raw = {};
|
|
58
103
|
try {
|
|
59
104
|
raw = getConfig(CONFIG_NAME);
|
|
60
105
|
} catch { /* absent or unreadable = no names yet */ }
|
|
61
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
...Object.fromEntries(KINDS.map(k => [k, cleanTagList(raw?.[k])])),
|
|
108
|
+
collectionTags: cleanTagMap(raw?.collectionTags)
|
|
109
|
+
};
|
|
62
110
|
}
|
|
63
111
|
|
|
64
112
|
function writeRegistry(reg) {
|
|
65
|
-
saveConfig(CONFIG_NAME,
|
|
113
|
+
saveConfig(CONFIG_NAME, {
|
|
114
|
+
...Object.fromEntries(KINDS.map(k => [k, cleanTagList(reg[k])])),
|
|
115
|
+
collectionTags: cleanTagMap(reg.collectionTags)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Every collection's stored list tags, `{slug: [tags]}` - GET /api/collections puts them on each row. */
|
|
120
|
+
export function collectionTagMap() {
|
|
121
|
+
return readRegistry().collectionTags;
|
|
66
122
|
}
|
|
67
123
|
|
|
68
|
-
|
|
124
|
+
// ---- Tool tags ----
|
|
125
|
+
|
|
126
|
+
/** An unknown plugin's tag from its slug: "scraper-pro" -> "Scraper Pro". */
|
|
127
|
+
export function titleCaseSlug(slug) {
|
|
128
|
+
return String(slug || '').split(/[-_\s]+/).filter(Boolean).map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The slug of the Tool that owns an item of a kind, or ''. */
|
|
132
|
+
export function ownerOf(kind, raw) {
|
|
133
|
+
if (!raw) return '';
|
|
134
|
+
let owner = '';
|
|
135
|
+
if (kind === 'collections') owner = raw.plugin || PRESET_TOOL_COLLECTIONS[raw.slug] || '';
|
|
136
|
+
else if (kind === 'blocks') owner = raw.meta?.plugin || '';
|
|
137
|
+
else owner = raw.plugin || '';
|
|
138
|
+
return typeof owner === 'string' ? owner : '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const TOOL_NAMES_TTL = 30_000;
|
|
142
|
+
let toolNamesCache = null;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Every Tool's display name by slug: the built-in Tools (services/tools.js),
|
|
146
|
+
* then each plugin manifest's `displayName`. Cached briefly - every list load
|
|
147
|
+
* asks, and discoverPlugins() reads every manifest.
|
|
148
|
+
*
|
|
149
|
+
* @returns {Promise<Object.<string, string>>}
|
|
150
|
+
*/
|
|
151
|
+
export async function toolNames() {
|
|
152
|
+
if (toolNamesCache && Date.now() - toolNamesCache.at < TOOL_NAMES_TTL) return toolNamesCache.names;
|
|
153
|
+
const names = Object.fromEntries(CORE_TOOLS.map(t => [t.name, t.displayName]));
|
|
154
|
+
try {
|
|
155
|
+
const {discoverPlugins} = await import('./plugins.js');
|
|
156
|
+
for (const p of await discoverPlugins()) {
|
|
157
|
+
const display = typeof p.displayName === 'string' ? normaliseTag(p.displayName) : '';
|
|
158
|
+
if (display && typeof p.name === 'string') names[p.name] = display;
|
|
159
|
+
}
|
|
160
|
+
} catch { /* no plugins folder: the built-in names are enough */ }
|
|
161
|
+
toolNamesCache = {at: Date.now(), names};
|
|
162
|
+
return names;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Forget the cached Tool names (tests; after a plugin install). */
|
|
166
|
+
export function invalidateToolNames() { toolNamesCache = null; }
|
|
167
|
+
|
|
168
|
+
/** The Tool tag an item wears, or ''. */
|
|
169
|
+
function toolTagFor(kind, raw, names) {
|
|
170
|
+
const owner = ownerOf(kind, raw);
|
|
171
|
+
return owner ? normaliseTag(names[owner] || titleCaseSlug(owner)) : '';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The items of a kind as `{id, tags, raw}`, through the same listers the routes use. */
|
|
69
175
|
async function items(kind) {
|
|
70
176
|
if (kind === 'pages') return (await listPages()).map(p => ({id: p.urlPath, tags: cleanTagList(p.adminTags), raw: p}));
|
|
177
|
+
if (kind === 'collections') {
|
|
178
|
+
const map = readRegistry().collectionTags;
|
|
179
|
+
return (await listCollections()).map(c => ({id: c.slug, tags: cleanTagList(map[c.slug]), raw: c}));
|
|
180
|
+
}
|
|
71
181
|
return (await listBlocks()).map(b => ({id: b.name, tags: cleanTagList(b.meta?.adminTags), raw: b}));
|
|
72
182
|
}
|
|
73
183
|
|
|
74
184
|
async function writeItemTags(kind, id, tags) {
|
|
75
185
|
const clean = cleanTagList(tags);
|
|
76
186
|
if (kind === 'pages') await setPageFrontmatter(id, {adminTags: clean.length ? clean : undefined});
|
|
77
|
-
else
|
|
187
|
+
else if (kind === 'collections') {
|
|
188
|
+
const reg = readRegistry();
|
|
189
|
+
if (clean.length) reg.collectionTags[id] = clean;
|
|
190
|
+
else delete reg.collectionTags[id];
|
|
191
|
+
writeRegistry(reg);
|
|
192
|
+
} else await setBlockMeta(id, {adminTags: clean.length ? clean : undefined});
|
|
78
193
|
return clean;
|
|
79
194
|
}
|
|
80
195
|
|
|
81
196
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
197
|
+
* Names a manual tag may not take, lower-cased: every known Tool's display
|
|
198
|
+
* name, plus the Tool tags worn by items of `kind` (an unknown plugin's
|
|
199
|
+
* title-cased slug).
|
|
200
|
+
*/
|
|
201
|
+
async function reservedNames(kind) {
|
|
202
|
+
const names = await toolNames();
|
|
203
|
+
const out = new Set(Object.values(names).map(n => normaliseTag(n).toLowerCase()));
|
|
204
|
+
for (const it of await items(kind)) {
|
|
205
|
+
const t = toolTagFor(kind, it.raw, names);
|
|
206
|
+
if (t) out.add(t.toLowerCase());
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The Tool tags items of `kind` actually wear, lower-cased - the ones that cannot be renamed or deleted. */
|
|
212
|
+
async function wornToolTags(kind) {
|
|
213
|
+
const names = await toolNames();
|
|
214
|
+
const out = new Set();
|
|
215
|
+
for (const it of await items(kind)) {
|
|
216
|
+
const t = toolTagFor(kind, it.raw, names);
|
|
217
|
+
if (t) out.add(t.toLowerCase());
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The manual tags an admin save may store: the incoming list without any
|
|
224
|
+
* Tool's name - except names the item already wore (a tag kept from before a
|
|
225
|
+
* Tool took its name). For saves that do not go through the tag routes (a page
|
|
226
|
+
* or block saved from its editor).
|
|
227
|
+
*/
|
|
228
|
+
export async function keepManualTags(kind, incoming, stored = []) {
|
|
229
|
+
if (!Array.isArray(incoming)) return incoming;
|
|
230
|
+
const reserved = await reservedNames(kind);
|
|
231
|
+
const had = cleanTagList(stored);
|
|
232
|
+
return cleanTagList(incoming).filter(t => !reserved.has(t.toLowerCase()) || had.some(h => same(h, t)));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function assertNotToolName(kind, list) {
|
|
236
|
+
if (!list.length) return;
|
|
237
|
+
const reserved = await reservedNames(kind);
|
|
238
|
+
const clash = list.find(t => reserved.has(normaliseTag(t).toLowerCase()));
|
|
239
|
+
if (clash) throw badTag(`"${normaliseTag(clash)}" is a Tool's tag - the Tool adds it itself. Pick another name.`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Every tag of a kind with how many items wear it: the registry's names, any
|
|
244
|
+
* name only found on items, and the Tool tags (`tool: true`) of the Tools that
|
|
245
|
+
* own any visible item - alphabetical. An item wearing a manual tag spelled
|
|
246
|
+
* like its own Tool tag counts once.
|
|
84
247
|
*
|
|
85
248
|
* @param {string} kind
|
|
86
249
|
* @param {(item: object) => boolean} [visible] - the caller's scope filter
|
|
87
|
-
* @returns {Promise<{name: string, count: number}[]>}
|
|
250
|
+
* @returns {Promise<{name: string, count: number, tool?: true}[]>}
|
|
88
251
|
*/
|
|
89
252
|
export async function listTags(kind, visible = () => true) {
|
|
90
253
|
assertKind(kind);
|
|
91
254
|
const names = [...readRegistry()[kind]];
|
|
255
|
+
const tools = [];
|
|
92
256
|
const counts = new Map();
|
|
257
|
+
const nameMap = await toolNames();
|
|
93
258
|
for (const it of await items(kind)) {
|
|
94
259
|
if (!visible(it.raw)) continue;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
260
|
+
const toolTag = toolTagFor(kind, it.raw, nameMap);
|
|
261
|
+
if (toolTag && !tools.some(n => same(n, toolTag))) tools.push(toolTag);
|
|
262
|
+
for (const t of cleanTagList([...(toolTag ? [toolTag] : []), ...it.tags])) {
|
|
263
|
+
if (!same(t, toolTag) && !names.some(n => same(n, t))) names.push(t);
|
|
264
|
+
const key = t.toLowerCase();
|
|
99
265
|
counts.set(key, (counts.get(key) || 0) + 1);
|
|
100
266
|
}
|
|
101
267
|
}
|
|
102
|
-
|
|
268
|
+
const isTool = (n) => tools.some(t => same(t, n));
|
|
269
|
+
return cleanTagList([...tools, ...names])
|
|
103
270
|
.sort((a, b) => a.localeCompare(b, undefined, {sensitivity: 'base'}))
|
|
104
|
-
.map(name => ({name, count: counts.get(name.toLowerCase()) || 0}));
|
|
271
|
+
.map(name => ({name, count: counts.get(name.toLowerCase()) || 0, ...(isTool(name) && {tool: true})}));
|
|
105
272
|
}
|
|
106
273
|
|
|
107
274
|
/** Add a name to the registry (no item changes). Returns the stored spelling. */
|
|
108
275
|
async function addTagNow(kind, name) {
|
|
109
276
|
assertKind(kind);
|
|
110
277
|
const tag = normaliseTag(name);
|
|
111
|
-
if (!tag)
|
|
112
|
-
const err = new Error('A tag needs a name.');
|
|
113
|
-
err.code = 'BAD_TAG';
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
278
|
+
if (!tag) throw badTag('A tag needs a name.');
|
|
116
279
|
const reg = readRegistry();
|
|
117
280
|
const existing = reg[kind].find(n => same(n, tag));
|
|
118
281
|
if (existing) return existing;
|
|
282
|
+
await assertNotToolName(kind, [tag]);
|
|
119
283
|
reg[kind].push(tag);
|
|
120
284
|
writeRegistry(reg);
|
|
121
285
|
return tag;
|
|
122
286
|
}
|
|
123
287
|
|
|
288
|
+
/** One item's stored (manual) tags, or null when the item does not exist. */
|
|
289
|
+
async function storedTags(kind, id) {
|
|
290
|
+
if (kind === 'pages') {
|
|
291
|
+
const page = await getPage(id);
|
|
292
|
+
return page ? cleanTagList(page.adminTags) : null;
|
|
293
|
+
}
|
|
294
|
+
if (kind === 'collections') {
|
|
295
|
+
const schema = await getCollection(id).catch(() => null);
|
|
296
|
+
return schema ? cleanTagList(readRegistry().collectionTags[id]) : null;
|
|
297
|
+
}
|
|
298
|
+
const block = await getBlock(id).catch(() => null);
|
|
299
|
+
return block ? cleanTagList(block.meta?.adminTags) : null;
|
|
300
|
+
}
|
|
301
|
+
|
|
124
302
|
/**
|
|
125
303
|
* Change one item's tags: `tags` replaces the list, `add` / `remove` patch the
|
|
126
304
|
* stored one (read afresh here, so two quick changes from the menu both land).
|
|
127
|
-
* Names it brings that the registry lacks are added to it.
|
|
305
|
+
* Names it brings that the registry lacks are added to it. A name the item
|
|
306
|
+
* does not wear yet may not be a Tool tag's.
|
|
128
307
|
*
|
|
129
308
|
* @param {string} kind
|
|
130
|
-
* @param {string} id - urlPath or
|
|
309
|
+
* @param {string} id - urlPath, block name or collection slug
|
|
131
310
|
* @param {{tags?: string[], add?: string[], remove?: string[]}} change
|
|
132
311
|
* @returns {Promise<string[]>} the stored list
|
|
133
312
|
*/
|
|
134
313
|
async function changeItemTagsNow(kind, id, {tags, add = [], remove = []} = {}) {
|
|
135
314
|
assertKind(kind);
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const err = new Error(`Not found: ${id}`);
|
|
142
|
-
err.code = 'ENOENT';
|
|
143
|
-
throw err;
|
|
144
|
-
}
|
|
145
|
-
const stored = cleanTagList(kind === 'pages' ? item.adminTags : item.meta?.adminTags);
|
|
146
|
-
next = [...stored, ...(Array.isArray(add) ? add : [])]
|
|
147
|
-
.filter(t => !(Array.isArray(remove) ? remove : []).some(r => same(r, t)));
|
|
315
|
+
const stored = await storedTags(kind, id);
|
|
316
|
+
if (!stored) {
|
|
317
|
+
const err = new Error(`Not found: ${id}`);
|
|
318
|
+
err.code = 'ENOENT';
|
|
319
|
+
throw err;
|
|
148
320
|
}
|
|
321
|
+
const next = Array.isArray(tags) ? tags
|
|
322
|
+
: [...stored, ...(Array.isArray(add) ? add : [])]
|
|
323
|
+
.filter(t => !(Array.isArray(remove) ? remove : []).some(r => same(r, t)));
|
|
324
|
+
// Only names the item does not already wear are checked: a manual tag stored
|
|
325
|
+
// before a Tool took its name can still be kept or removed.
|
|
326
|
+
await assertNotToolName(kind, cleanTagList(next).filter(t => !stored.some(s => same(s, t))));
|
|
149
327
|
const clean = await writeItemTags(kind, id, next);
|
|
150
328
|
const reg = readRegistry();
|
|
151
329
|
const fresh = clean.filter(t => !reg[kind].some(n => same(n, t)));
|
|
@@ -159,18 +337,21 @@ async function changeItemTagsNow(kind, id, {tags, add = [], remove = []} = {}) {
|
|
|
159
337
|
/**
|
|
160
338
|
* Rename a tag on every item the caller may see. Renaming onto an existing
|
|
161
339
|
* tag merges the two. An item outside the caller's projects keeps the old
|
|
162
|
-
* name, which then still lists (found on an item).
|
|
340
|
+
* name, which then still lists (found on an item). A Tool tag is neither
|
|
341
|
+
* renamed nor a rename's target.
|
|
163
342
|
*
|
|
164
343
|
* @returns {Promise<{name: string, changed: number}>}
|
|
165
344
|
*/
|
|
166
345
|
async function renameTagNow(kind, from, to, visible = () => true) {
|
|
167
346
|
assertKind(kind);
|
|
168
347
|
const target = normaliseTag(to);
|
|
169
|
-
if (!target)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
348
|
+
if (!target) throw badTag('A tag needs a name.');
|
|
349
|
+
// Only a Tool tag items of this kind wear is fixed; a manual tag that happens to share a Tool's name
|
|
350
|
+
// (made before that Tool existed) can still be renamed away or deleted.
|
|
351
|
+
if ((await wornToolTags(kind)).has(normaliseTag(from).toLowerCase())) {
|
|
352
|
+
throw badTag('A Tool\'s tag is added by the Tool - it cannot be renamed.');
|
|
173
353
|
}
|
|
354
|
+
await assertNotToolName(kind, [target]);
|
|
174
355
|
let changed = 0;
|
|
175
356
|
for (const it of await items(kind)) {
|
|
176
357
|
if (!visible(it.raw) || !it.tags.some(t => same(t, from))) continue;
|
|
@@ -185,11 +366,15 @@ async function renameTagNow(kind, from, to, visible = () => true) {
|
|
|
185
366
|
|
|
186
367
|
/**
|
|
187
368
|
* Delete a tag: it comes off every item the caller may see. The items stay.
|
|
369
|
+
* A Tool tag cannot be deleted.
|
|
188
370
|
*
|
|
189
371
|
* @returns {Promise<{changed: number}>}
|
|
190
372
|
*/
|
|
191
373
|
async function deleteTagNow(kind, name, visible = () => true) {
|
|
192
374
|
assertKind(kind);
|
|
375
|
+
if ((await wornToolTags(kind)).has(normaliseTag(name).toLowerCase())) {
|
|
376
|
+
throw badTag('A Tool\'s tag is added by the Tool - it cannot be deleted.');
|
|
377
|
+
}
|
|
193
378
|
let changed = 0;
|
|
194
379
|
for (const it of await items(kind)) {
|
|
195
380
|
if (!visible(it.raw) || !it.tags.some(t => same(t, name))) continue;
|
|
@@ -202,6 +387,15 @@ async function deleteTagNow(kind, name, visible = () => true) {
|
|
|
202
387
|
return {changed};
|
|
203
388
|
}
|
|
204
389
|
|
|
390
|
+
/** A collection is gone: drop its entry from the tag map. */
|
|
391
|
+
function dropCollectionTagsNow(slug) {
|
|
392
|
+
const reg = readRegistry();
|
|
393
|
+
if (!Object.hasOwn(reg.collectionTags, slug)) return false;
|
|
394
|
+
delete reg.collectionTags[slug];
|
|
395
|
+
writeRegistry(reg);
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
|
|
205
399
|
// Every change runs one after another: each is a read-modify-write of item
|
|
206
400
|
// files and the registry, and two interleaved (a rename while someone tags a
|
|
207
401
|
// page) would lose one of them.
|
|
@@ -218,3 +412,5 @@ export const changeItemTags = (kind, id, change) => serial(() => changeItemTagsN
|
|
|
218
412
|
export const setItemTags = (kind, id, tags) => changeItemTags(kind, id, {tags});
|
|
219
413
|
export const renameTag = (kind, from, to, visible) => serial(() => renameTagNow(kind, from, to, visible));
|
|
220
414
|
export const deleteTag = (kind, name, visible) => serial(() => deleteTagNow(kind, name, visible));
|
|
415
|
+
/** A collection was deleted: its tags go too. Resolves true when it had some. */
|
|
416
|
+
export const dropCollectionTags = (slug) => serial(() => dropCollectionTagsNow(slug));
|
|
@@ -1748,6 +1748,10 @@ export async function renderCollectionFragment(attrs, { extraFilter = null, scop
|
|
|
1748
1748
|
let fields = schema.fields || [];
|
|
1749
1749
|
if (fieldFilter?.length) {
|
|
1750
1750
|
fields = fieldFilter.map(name => fields.find(f => f.name === name) || { name, label: name });
|
|
1751
|
+
} else {
|
|
1752
|
+
// A field marked "not in lists" (listHidden) is left out unless fields="" names it.
|
|
1753
|
+
const shown = fields.filter(f => f.listHidden !== true);
|
|
1754
|
+
if (shown.length) fields = shown;
|
|
1751
1755
|
}
|
|
1752
1756
|
if (!fields.length && entries.length) {
|
|
1753
1757
|
fields = Object.keys(entries[0].data || {}).map(k => ({ name: k, label: k }));
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<link rel="stylesheet" href="/dist/domma/themes/domma-themes.css">
|
|
26
26
|
|
|
27
27
|
<!-- Site CSS -->
|
|
28
|
-
<link rel="stylesheet" href="/public/css/site.css?v=
|
|
28
|
+
<link rel="stylesheet" href="/public/css/site.css?v=20261102-cb-full-width">
|
|
29
29
|
<link rel="stylesheet" href="/public/css/forms.css?v=20261031-forms-reduce-motion">
|
|
30
30
|
<!-- Menu item hover / current-page effects. Loaded after site.css so a
|
|
31
31
|
menu's own highlight wins over the blanket link styling there. -->
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
searchable / filterable / sortable / paginate attributes) -->
|
|
184
184
|
<!-- Its range-filter arithmetic; a module that runs first and sets window.DommaCollectionRange -->
|
|
185
185
|
<script src="/public/js/collection-range.mjs?v=20261025-range-slider" type="module"></script>
|
|
186
|
-
<script src="/public/js/collection-browser.js?v=
|
|
186
|
+
<script src="/public/js/collection-browser.js?v=20261102-cb-full-width" defer></script>
|
|
187
187
|
<!-- Core Forms logic engine (must run before forms.js and site.js) -->
|
|
188
188
|
<script src="/public/js/form-logic-engine.js?v=20261031-forms-reduce-motion" defer></script>
|
|
189
189
|
|