includio-cms 0.5.3 → 0.5.5
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 +41 -0
- package/ROADMAP.md +16 -0
- package/dist/admin/api/rest/handler.d.ts +7 -0
- package/dist/admin/api/rest/handler.js +116 -0
- package/dist/admin/api/rest/middleware/apiKey.d.ts +6 -0
- package/dist/admin/api/rest/middleware/apiKey.js +45 -0
- package/dist/admin/api/rest/routes/collections.d.ts +5 -0
- package/dist/admin/api/rest/routes/collections.js +104 -0
- package/dist/admin/api/rest/routes/entries.d.ts +2 -0
- package/dist/admin/api/rest/routes/entries.js +37 -0
- package/dist/admin/api/rest/routes/languages.d.ts +1 -0
- package/dist/admin/api/rest/routes/languages.js +5 -0
- package/dist/admin/api/rest/routes/schema.d.ts +2 -0
- package/dist/admin/api/rest/routes/schema.js +78 -0
- package/dist/admin/api/rest/routes/singletons.d.ts +3 -0
- package/dist/admin/api/rest/routes/singletons.js +60 -0
- package/dist/admin/auth-client.d.ts +7 -7
- package/dist/admin/client/collection/collection-entries.svelte +56 -5
- package/dist/admin/client/collection/data-table.svelte +127 -18
- package/dist/admin/client/collection/data-table.svelte.d.ts +2 -0
- package/dist/admin/components/fields/relation-field.svelte +13 -10
- package/dist/admin/components/layout/nav-collections.svelte +2 -1
- package/dist/admin/components/layout/nav-forms.svelte +2 -1
- package/dist/admin/components/layout/nav-singletons.svelte +2 -1
- package/dist/admin/remote/entry.remote.d.ts +9 -1
- package/dist/admin/remote/entry.remote.js +14 -2
- package/dist/cli/scaffold/admin.js +8 -0
- package/dist/core/cms.d.ts +2 -1
- package/dist/core/cms.js +2 -0
- package/dist/core/server/entries/operations/get.js +2 -1
- package/dist/core/server/entries/operations/update.d.ts +1 -0
- package/dist/core/server/entries/operations/update.js +5 -1
- package/dist/db-postgres/schema/entry.d.ts +17 -0
- package/dist/db-postgres/schema/entry.js +4 -2
- package/dist/server/auth.d.ts +6 -6
- package/dist/sveltekit/server/handle.js +1 -0
- package/dist/types/cms.d.ts +7 -0
- package/dist/types/collections.d.ts +2 -0
- package/dist/types/entries.d.ts +7 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/updates/0.5.4/index.d.ts +2 -0
- package/dist/updates/0.5.4/index.js +15 -0
- package/dist/updates/0.5.5/index.d.ts +2 -0
- package/dist/updates/0.5.5/index.js +20 -0
- package/dist/updates/index.js +3 -1
- package/package.json +6 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getRawCollectionEntryLabel } from '../../utils/entryLabel.js';
|
|
3
3
|
import { getEntryThumbnail } from '../../utils/entryThumbnail.js';
|
|
4
|
+
import { arrayMove } from '../../utils/arrayMove.js';
|
|
4
5
|
import { getRemotes } from '../../../sveltekit/index.js';
|
|
5
6
|
import type { CollectionConfigWithType } from '../../../types/collections.js';
|
|
6
7
|
import DataTable from './data-table.svelte';
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
import type { InterfaceLanguage } from '../../../types/languages.js';
|
|
12
13
|
import { useInterfaceLanguage } from '../../state/interface-language.svelte.js';
|
|
13
14
|
import { getEntryStatus } from '../entry/utils.js';
|
|
15
|
+
import { getLocalizedLabel } from '../../utils/collectionLabel.js';
|
|
14
16
|
import * as AlertDialog from '../../../components/ui/alert-dialog/index.js';
|
|
15
17
|
import { toast } from 'svelte-sonner';
|
|
16
18
|
import StatusBadge from './status-badge.svelte';
|
|
@@ -110,6 +112,7 @@
|
|
|
110
112
|
thumbnail: string | null;
|
|
111
113
|
searchText: string;
|
|
112
114
|
a11yWarnings: number;
|
|
115
|
+
customData: Record<string, unknown>;
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
type Props = {
|
|
@@ -140,8 +143,14 @@
|
|
|
140
143
|
// Is the current filter for archived entries?
|
|
141
144
|
const isArchivedFilter = $derived(viewState.statusFilter === 'archived');
|
|
142
145
|
|
|
146
|
+
const isOrderable = $derived(!!collection.orderable);
|
|
147
|
+
|
|
143
148
|
// Build orderBy from sorting state for server-side mode
|
|
144
149
|
const serverOrderBy = $derived.by(() => {
|
|
150
|
+
// When orderable, always sort by sortOrder
|
|
151
|
+
if (isOrderable) {
|
|
152
|
+
return { column: 'sortOrder' as const, direction: 'asc' as const };
|
|
153
|
+
}
|
|
145
154
|
if (!viewState.sorting.length) return undefined;
|
|
146
155
|
const { id, desc } = viewState.sorting[0];
|
|
147
156
|
if (id === 'createdAt' || id === 'updatedAt') {
|
|
@@ -240,6 +249,23 @@
|
|
|
240
249
|
}),
|
|
241
250
|
size: 140
|
|
242
251
|
},
|
|
252
|
+
// Custom list columns from collection config
|
|
253
|
+
...(collection.listColumns ?? []).map((fieldSlug) => {
|
|
254
|
+
const fieldConfig = collection.fields.find((f) => f.slug === fieldSlug);
|
|
255
|
+
const headerLabel = fieldConfig?.label
|
|
256
|
+
? getLocalizedLabel(fieldConfig.label, interfaceLanguage.current)
|
|
257
|
+
: fieldSlug;
|
|
258
|
+
return {
|
|
259
|
+
id: `custom_${fieldSlug}`,
|
|
260
|
+
header: headerLabel,
|
|
261
|
+
cell: (info: { row: { original: CollectionDataTableRow } }) => {
|
|
262
|
+
const value = info.row.original.customData[fieldSlug];
|
|
263
|
+
return String(value ?? '');
|
|
264
|
+
},
|
|
265
|
+
enableSorting: false,
|
|
266
|
+
size: 120
|
|
267
|
+
} satisfies ColumnDef<CollectionDataTableRow>;
|
|
268
|
+
}),
|
|
243
269
|
{
|
|
244
270
|
id: 'actions',
|
|
245
271
|
header: '',
|
|
@@ -331,6 +357,19 @@
|
|
|
331
357
|
|
|
332
358
|
function mapEntryToRow(entry: RawEntry): CollectionDataTableRow {
|
|
333
359
|
const data = entry.draftVersion?.data || entry.publishedVersion?.data || {};
|
|
360
|
+
const customData: Record<string, unknown> = {};
|
|
361
|
+
if (collection.listColumns) {
|
|
362
|
+
for (const fieldSlug of collection.listColumns) {
|
|
363
|
+
const fieldData = (data as Record<string, unknown>)[fieldSlug];
|
|
364
|
+
// For localized fields, extract current content language value
|
|
365
|
+
if (fieldData && typeof fieldData === 'object' && !Array.isArray(fieldData)) {
|
|
366
|
+
const localized = fieldData as Record<string, unknown>;
|
|
367
|
+
customData[fieldSlug] = localized[contentLanguage.current] ?? Object.values(localized)[0] ?? '';
|
|
368
|
+
} else {
|
|
369
|
+
customData[fieldSlug] = fieldData ?? '';
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
334
373
|
return {
|
|
335
374
|
id: entry.id,
|
|
336
375
|
name: getRawCollectionEntryLabel(entry, collection, contentLanguage.current),
|
|
@@ -341,7 +380,8 @@
|
|
|
341
380
|
updatedAt: new Date(entry.updatedAt),
|
|
342
381
|
thumbnail: getEntryThumbnail(data as Record<string, unknown>, collection),
|
|
343
382
|
searchText: getSearchText(entry),
|
|
344
|
-
a11yWarnings: countA11yWarnings(entry)
|
|
383
|
+
a11yWarnings: countA11yWarnings(entry),
|
|
384
|
+
customData
|
|
345
385
|
};
|
|
346
386
|
}
|
|
347
387
|
|
|
@@ -404,6 +444,14 @@
|
|
|
404
444
|
refreshQueries();
|
|
405
445
|
}
|
|
406
446
|
|
|
447
|
+
async function handleReorder(items: CollectionDataTableRow[], fromIndex: number, toIndex: number) {
|
|
448
|
+
if (!isOrderable || items.length === 0) return;
|
|
449
|
+
const reordered = arrayMove(items, fromIndex, toIndex);
|
|
450
|
+
const orderedIds = reordered.map((item) => item.id);
|
|
451
|
+
await remotes.reorderEntriesCommand({ orderedIds });
|
|
452
|
+
refreshQueries();
|
|
453
|
+
}
|
|
454
|
+
|
|
407
455
|
async function handleBulkDelete(items: CollectionDataTableRow[]) {
|
|
408
456
|
const idsToDelete = selectedIndices.map((idx) => items[idx]?.id).filter(Boolean);
|
|
409
457
|
for (const id of idsToDelete) {
|
|
@@ -439,8 +487,7 @@
|
|
|
439
487
|
? result.total
|
|
440
488
|
: filteredRows.length}
|
|
441
489
|
{@const pageCount = Math.ceil(totalItems / viewState.pageSize)}
|
|
442
|
-
{@const displayItems =
|
|
443
|
-
useServerPagination && !viewState.statusFilter
|
|
490
|
+
{@const displayItems = useServerPagination && !viewState.statusFilter
|
|
444
491
|
? filteredRows
|
|
445
492
|
: filteredRows.slice(
|
|
446
493
|
viewState.pageIndex * viewState.pageSize,
|
|
@@ -474,7 +521,7 @@
|
|
|
474
521
|
<DataTable
|
|
475
522
|
data={displayItems}
|
|
476
523
|
{columns}
|
|
477
|
-
enableSorting
|
|
524
|
+
enableSorting={!isOrderable}
|
|
478
525
|
enableFiltering
|
|
479
526
|
enableSelection
|
|
480
527
|
enablePagination
|
|
@@ -490,12 +537,14 @@
|
|
|
490
537
|
viewState.pageIndex = p.pageIndex;
|
|
491
538
|
}}
|
|
492
539
|
tableRef={(t) => (tableInstance = t)}
|
|
540
|
+
orderable={isOrderable}
|
|
541
|
+
onReorder={(from, to) => handleReorder(displayItems, from, to)}
|
|
493
542
|
/>
|
|
494
543
|
{:else}
|
|
495
544
|
<DataTable
|
|
496
545
|
data={displayItems}
|
|
497
546
|
{columns}
|
|
498
|
-
enableSorting
|
|
547
|
+
enableSorting={!isOrderable}
|
|
499
548
|
enableFiltering
|
|
500
549
|
enableSelection
|
|
501
550
|
enablePagination
|
|
@@ -508,6 +557,8 @@
|
|
|
508
557
|
viewState.pageIndex = p.pageIndex;
|
|
509
558
|
}}
|
|
510
559
|
tableRef={(t) => (tableInstance = t)}
|
|
560
|
+
orderable={isOrderable}
|
|
561
|
+
onReorder={(from, to) => handleReorder(displayItems, from, to)}
|
|
511
562
|
/>
|
|
512
563
|
{/if}
|
|
513
564
|
</div>
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
import * as Table from '../../../components/ui/table/index.js';
|
|
16
16
|
import { useInterfaceLanguage } from '../../state/interface-language.svelte.js';
|
|
17
17
|
import type { InterfaceLanguage } from '../../../types/languages.js';
|
|
18
|
+
import { droppable, draggable, dndState } from '@thisux/sveltednd';
|
|
19
|
+
import { flip } from 'svelte/animate';
|
|
18
20
|
|
|
19
21
|
type DataTableProps<TData, TValue> = {
|
|
20
22
|
columns: ColumnDef<TData, TValue>[];
|
|
@@ -35,6 +37,8 @@
|
|
|
35
37
|
pageCount?: number;
|
|
36
38
|
rowCount?: number;
|
|
37
39
|
emptyMessage?: string;
|
|
40
|
+
orderable?: boolean;
|
|
41
|
+
onReorder?: (fromIndex: number, toIndex: number) => void;
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
let {
|
|
@@ -55,9 +59,18 @@
|
|
|
55
59
|
manualPagination: manualPaginationProp = false,
|
|
56
60
|
pageCount: pageCountProp,
|
|
57
61
|
rowCount: rowCountProp,
|
|
58
|
-
emptyMessage
|
|
62
|
+
emptyMessage,
|
|
63
|
+
orderable = false,
|
|
64
|
+
onReorder
|
|
59
65
|
}: DataTableProps<TData, TValue> = $props();
|
|
60
66
|
|
|
67
|
+
let liveRegionMessage = $state('');
|
|
68
|
+
let dropProcessing = false;
|
|
69
|
+
|
|
70
|
+
const matchesReducedMotion = typeof window !== 'undefined'
|
|
71
|
+
? window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
72
|
+
: false;
|
|
73
|
+
|
|
61
74
|
const interfaceLanguage = useInterfaceLanguage();
|
|
62
75
|
|
|
63
76
|
const defaultEmptyMessages: Record<InterfaceLanguage, string> = {
|
|
@@ -113,10 +126,17 @@
|
|
|
113
126
|
});
|
|
114
127
|
</script>
|
|
115
128
|
|
|
116
|
-
|
|
129
|
+
{#if orderable}
|
|
130
|
+
<div aria-live="polite" aria-atomic="true" class="sr-only">{liveRegionMessage}</div>
|
|
131
|
+
{/if}
|
|
132
|
+
|
|
133
|
+
<Table.Root aria-roledescription={orderable ? 'sortable list' : undefined}>
|
|
117
134
|
<Table.Header class="bg-muted sticky top-0 z-10">
|
|
118
135
|
{#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
|
|
119
136
|
<Table.Row class="border-b-0 hover:bg-transparent">
|
|
137
|
+
{#if orderable}
|
|
138
|
+
<Table.Head class="text-[11px] font-bold uppercase tracking-[0.04em] text-muted-foreground h-10 w-10"></Table.Head>
|
|
139
|
+
{/if}
|
|
120
140
|
{#each headerGroup.headers as header (header.id)}
|
|
121
141
|
<Table.Head class="text-[11px] font-bold uppercase tracking-[0.04em] text-muted-foreground h-10">
|
|
122
142
|
{#if !header.isPlaceholder}
|
|
@@ -131,23 +151,112 @@
|
|
|
131
151
|
{/each}
|
|
132
152
|
</Table.Header>
|
|
133
153
|
<Table.Body>
|
|
134
|
-
{#
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
{#if orderable}
|
|
155
|
+
{#each table.getRowModel().rows as row, i (row.id)}
|
|
156
|
+
{@const totalRows = table.getRowModel().rows.length}
|
|
157
|
+
<tr
|
|
158
|
+
use:droppable={{
|
|
159
|
+
container: i.toString(),
|
|
160
|
+
callbacks: {
|
|
161
|
+
onDrop: (state) => {
|
|
162
|
+
if (dropProcessing) return;
|
|
163
|
+
dropProcessing = true;
|
|
164
|
+
const fromIndex = parseInt(state.sourceContainer ?? '');
|
|
165
|
+
const toIndex = parseInt(state.targetContainer ?? '');
|
|
166
|
+
if (!isNaN(fromIndex) && !isNaN(toIndex)) {
|
|
167
|
+
onReorder?.(fromIndex, toIndex);
|
|
168
|
+
}
|
|
169
|
+
dndState.isDragging = false;
|
|
170
|
+
dndState.draggedItem = null;
|
|
171
|
+
dndState.sourceContainer = '';
|
|
172
|
+
dndState.targetContainer = null;
|
|
173
|
+
dndState.targetElement = null;
|
|
174
|
+
setTimeout(() => { dropProcessing = false; }, 50);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}}
|
|
178
|
+
animate:flip={{ duration: matchesReducedMotion ? 0 : 200 }}
|
|
179
|
+
data-slot="table-row"
|
|
180
|
+
data-state={row.getIsSelected() ? 'selected' : undefined}
|
|
181
|
+
class="hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors hover:bg-lavender-lighter/50 data-[state=selected]:bg-lavender-lighter/30 {i === totalRows - 1 ? 'border-b-0' : ''}"
|
|
182
|
+
>
|
|
183
|
+
<Table.Cell class="py-3 w-10">
|
|
184
|
+
<div class="flex items-center gap-1">
|
|
185
|
+
<div
|
|
186
|
+
use:draggable={{
|
|
187
|
+
container: i.toString(),
|
|
188
|
+
dragData: { index: i }
|
|
189
|
+
}}
|
|
190
|
+
class="text-muted-foreground hover:text-foreground cursor-grab"
|
|
191
|
+
role="button"
|
|
192
|
+
tabindex="0"
|
|
193
|
+
aria-label={`Drag to reorder, row ${i + 1} of ${totalRows}`}
|
|
194
|
+
aria-roledescription="draggable"
|
|
195
|
+
>
|
|
196
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>
|
|
197
|
+
</div>
|
|
198
|
+
<div class="flex flex-col">
|
|
199
|
+
{#if i > 0}
|
|
200
|
+
<button
|
|
201
|
+
type="button"
|
|
202
|
+
class="p-0.5 rounded text-muted-foreground hover:text-foreground"
|
|
203
|
+
aria-label={`Move up, row ${i + 1} of ${totalRows}`}
|
|
204
|
+
onclick={() => {
|
|
205
|
+
onReorder?.(i, i - 1);
|
|
206
|
+
liveRegionMessage = `Moved to position ${i} of ${totalRows}`;
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m18 15-6-6-6 6"/></svg>
|
|
210
|
+
</button>
|
|
211
|
+
{/if}
|
|
212
|
+
{#if i < totalRows - 1}
|
|
213
|
+
<button
|
|
214
|
+
type="button"
|
|
215
|
+
class="p-0.5 rounded text-muted-foreground hover:text-foreground"
|
|
216
|
+
aria-label={`Move down, row ${i + 1} of ${totalRows}`}
|
|
217
|
+
onclick={() => {
|
|
218
|
+
onReorder?.(i, i + 1);
|
|
219
|
+
liveRegionMessage = `Moved to position ${i + 2} of ${totalRows}`;
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m6 9 6 6 6-6"/></svg>
|
|
223
|
+
</button>
|
|
224
|
+
{/if}
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
142
227
|
</Table.Cell>
|
|
143
|
-
|
|
144
|
-
|
|
228
|
+
{#each row.getVisibleCells() as cell (cell.id)}
|
|
229
|
+
<Table.Cell class="py-3">
|
|
230
|
+
<FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
|
|
231
|
+
</Table.Cell>
|
|
232
|
+
{/each}
|
|
233
|
+
</tr>
|
|
234
|
+
{:else}
|
|
235
|
+
<Table.Row>
|
|
236
|
+
<Table.Cell colspan={columns.length + 1} class="h-24 text-center text-muted-foreground">
|
|
237
|
+
{emptyMessage ?? defaultEmptyMessages[interfaceLanguage.current]}
|
|
238
|
+
</Table.Cell>
|
|
239
|
+
</Table.Row>
|
|
240
|
+
{/each}
|
|
145
241
|
{:else}
|
|
146
|
-
|
|
147
|
-
<Table.
|
|
148
|
-
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
242
|
+
{#each table.getRowModel().rows as row, i (row.id)}
|
|
243
|
+
<Table.Row
|
|
244
|
+
data-state={row.getIsSelected() && 'selected'}
|
|
245
|
+
class="hover:bg-lavender-lighter/50 data-[state=selected]:bg-lavender-lighter/30 {i === table.getRowModel().rows.length - 1 ? 'border-b-0' : ''}"
|
|
246
|
+
>
|
|
247
|
+
{#each row.getVisibleCells() as cell (cell.id)}
|
|
248
|
+
<Table.Cell class="py-3">
|
|
249
|
+
<FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
|
|
250
|
+
</Table.Cell>
|
|
251
|
+
{/each}
|
|
252
|
+
</Table.Row>
|
|
253
|
+
{:else}
|
|
254
|
+
<Table.Row>
|
|
255
|
+
<Table.Cell colspan={columns.length} class="h-24 text-center text-muted-foreground">
|
|
256
|
+
{emptyMessage ?? defaultEmptyMessages[interfaceLanguage.current]}
|
|
257
|
+
</Table.Cell>
|
|
258
|
+
</Table.Row>
|
|
259
|
+
{/each}
|
|
260
|
+
{/if}
|
|
152
261
|
</Table.Body>
|
|
153
262
|
</Table.Root>
|
|
@@ -18,6 +18,8 @@ type DataTableProps<TData, TValue> = {
|
|
|
18
18
|
pageCount?: number;
|
|
19
19
|
rowCount?: number;
|
|
20
20
|
emptyMessage?: string;
|
|
21
|
+
orderable?: boolean;
|
|
22
|
+
onReorder?: (fromIndex: number, toIndex: number) => void;
|
|
21
23
|
};
|
|
22
24
|
declare function $$render<TData, TValue>(): {
|
|
23
25
|
props: DataTableProps<TData, TValue>;
|
|
@@ -82,16 +82,19 @@
|
|
|
82
82
|
|
|
83
83
|
untrack(() => {
|
|
84
84
|
loading = true;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
remotes.getCollection(collection).then((collectionConfig) => {
|
|
86
|
+
const entriesParams: Record<string, unknown> = { slug: collection, language: currentLang };
|
|
87
|
+
if (collectionConfig.orderable) {
|
|
88
|
+
entriesParams.orderBy = { column: 'sortOrder', direction: 'asc' };
|
|
89
|
+
}
|
|
90
|
+
remotes.getEntries(entriesParams).then((entries) => {
|
|
91
|
+
const options = entries.map((entry) => ({
|
|
92
|
+
label: getCollectionEntryLabel(entry, collectionConfig),
|
|
93
|
+
value: entry.id
|
|
94
|
+
}));
|
|
95
|
+
relationData = { collectionConfig, options };
|
|
96
|
+
loading = false;
|
|
97
|
+
});
|
|
95
98
|
});
|
|
96
99
|
});
|
|
97
100
|
});
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
const remotes = getRemotes();
|
|
13
13
|
|
|
14
14
|
function isActive(url: string) {
|
|
15
|
-
|
|
15
|
+
const pathname = page.url.pathname;
|
|
16
|
+
return pathname === url || pathname.startsWith(url + '/');
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async function loadCollections() {
|
|
@@ -6,7 +6,7 @@ export declare const getRawEntries: import("@sveltejs/kit").RemoteQueryFunction<
|
|
|
6
6
|
limit?: number | undefined;
|
|
7
7
|
offset?: number | undefined;
|
|
8
8
|
orderBy?: {
|
|
9
|
-
column: "createdAt" | "updatedAt";
|
|
9
|
+
column: "createdAt" | "updatedAt" | "sortOrder";
|
|
10
10
|
direction: "asc" | "desc";
|
|
11
11
|
} | undefined;
|
|
12
12
|
}, {
|
|
@@ -20,6 +20,10 @@ export declare const getEntries: import("@sveltejs/kit").RemoteQueryFunction<{
|
|
|
20
20
|
language?: string | undefined;
|
|
21
21
|
status?: "draft" | "published" | "scheduled" | "archived" | undefined;
|
|
22
22
|
slug?: string | undefined;
|
|
23
|
+
orderBy?: {
|
|
24
|
+
column: "createdAt" | "updatedAt" | "sortOrder";
|
|
25
|
+
direction: "asc" | "desc";
|
|
26
|
+
} | undefined;
|
|
23
27
|
}, import("../../types/entries.js").Entry[]>;
|
|
24
28
|
export declare const getEntry: import("@sveltejs/kit").RemoteQueryFunction<{
|
|
25
29
|
id?: string | undefined;
|
|
@@ -53,11 +57,15 @@ export declare const updateEntryCommand: import("@sveltejs/kit").RemoteCommand<{
|
|
|
53
57
|
publishedAt?: Date | null | undefined;
|
|
54
58
|
publishedVersionId?: string | null | undefined;
|
|
55
59
|
publishedBy?: string | null | undefined;
|
|
60
|
+
sortOrder?: number | null | undefined;
|
|
56
61
|
};
|
|
57
62
|
}, Promise<import("../../types/entries.js").DbEntry>>;
|
|
58
63
|
export declare const archiveEntryCommand: import("@sveltejs/kit").RemoteCommand<string, Promise<import("../../types/entries.js").DbEntry>>;
|
|
59
64
|
export declare const unarchiveEntryCommand: import("@sveltejs/kit").RemoteCommand<string, Promise<import("../../types/entries.js").DbEntry>>;
|
|
60
65
|
export declare const deleteEntryCommand: import("@sveltejs/kit").RemoteCommand<string, Promise<void>>;
|
|
66
|
+
export declare const reorderEntriesCommand: import("@sveltejs/kit").RemoteCommand<{
|
|
67
|
+
orderedIds: string[];
|
|
68
|
+
}, Promise<void>>;
|
|
61
69
|
export declare const getEntryVersion: import("@sveltejs/kit").RemoteQueryFunction<{
|
|
62
70
|
id: string;
|
|
63
71
|
language: string;
|
|
@@ -14,7 +14,7 @@ export const getRawEntries = query(z.object({
|
|
|
14
14
|
offset: z.number().int().nonnegative().optional(),
|
|
15
15
|
orderBy: z
|
|
16
16
|
.object({
|
|
17
|
-
column: z.enum(['createdAt', 'updatedAt']),
|
|
17
|
+
column: z.enum(['createdAt', 'updatedAt', 'sortOrder']),
|
|
18
18
|
direction: z.enum(['asc', 'desc'])
|
|
19
19
|
})
|
|
20
20
|
.optional()
|
|
@@ -32,7 +32,13 @@ export const getEntries = query(z.object({
|
|
|
32
32
|
dataLike: z.record(z.string(), z.unknown()).optional(),
|
|
33
33
|
language: z.string().optional(),
|
|
34
34
|
status: z.enum(entryStatuses).optional(),
|
|
35
|
-
slug: z.string().optional()
|
|
35
|
+
slug: z.string().optional(),
|
|
36
|
+
orderBy: z
|
|
37
|
+
.object({
|
|
38
|
+
column: z.enum(['createdAt', 'updatedAt', 'sortOrder']),
|
|
39
|
+
direction: z.enum(['asc', 'desc'])
|
|
40
|
+
})
|
|
41
|
+
.optional()
|
|
36
42
|
}), async (input) => {
|
|
37
43
|
return getEntriesOperation(input);
|
|
38
44
|
});
|
|
@@ -172,6 +178,12 @@ export const deleteEntryCommand = command(z.string().uuid(), async (id) => {
|
|
|
172
178
|
}
|
|
173
179
|
return getCMS().databaseAdapter.deleteEntry({ id });
|
|
174
180
|
});
|
|
181
|
+
export const reorderEntriesCommand = command(z.object({
|
|
182
|
+
orderedIds: z.array(z.string().uuid())
|
|
183
|
+
}), async ({ orderedIds }) => {
|
|
184
|
+
requireAuth();
|
|
185
|
+
await Promise.all(orderedIds.map((id, index) => updateEntry(id, { sortOrder: index })));
|
|
186
|
+
});
|
|
175
187
|
export const getEntryVersion = query(z.object({
|
|
176
188
|
id: z.string().uuid(),
|
|
177
189
|
language: z.string()
|
|
@@ -156,6 +156,14 @@ export * from 'includio-cms/admin/remote';
|
|
|
156
156
|
import { createAdminApiHandler } from 'includio-cms/admin/api/handler';
|
|
157
157
|
|
|
158
158
|
export const { GET, POST, PATCH, PUT, DELETE } = createAdminApiHandler();
|
|
159
|
+
`
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
path: 'admin/api/rest/[...restPath]/+server.ts',
|
|
163
|
+
content: `${GENERATED_COMMENT_TS}
|
|
164
|
+
import { createRestApiHandler } from 'includio-cms/admin/api/rest/handler';
|
|
165
|
+
|
|
166
|
+
export const { GET, POST, PUT, DELETE } = createRestApiHandler();
|
|
159
167
|
`
|
|
160
168
|
}
|
|
161
169
|
];
|
package/dist/core/cms.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DatabaseAdapter } from '../types/adapters/db.js';
|
|
2
2
|
import type { FilesAdapter } from '../types/adapters/files.js';
|
|
3
|
-
import type { CMSConfig, ICMS, MediaConfig } from '../types/cms.js';
|
|
3
|
+
import type { ApiKeyConfig, CMSConfig, ICMS, MediaConfig } from '../types/cms.js';
|
|
4
4
|
import type { CollectionConfigWithType } from '../types/collections.js';
|
|
5
5
|
import type { Language } from '../types/languages.js';
|
|
6
6
|
import type { SingleConfigWithType } from '../types/singles.js';
|
|
@@ -22,6 +22,7 @@ export declare class CMS implements ICMS {
|
|
|
22
22
|
languages: Language[];
|
|
23
23
|
mediaConfig: MediaConfig;
|
|
24
24
|
plugins: PluginConfig[];
|
|
25
|
+
apiKeys: ApiKeyConfig[];
|
|
25
26
|
constructor(config: CMSConfig);
|
|
26
27
|
getBySlug(slug: string): CollectionConfigWithType | SingleConfigWithType;
|
|
27
28
|
getFormBySlug(slug: string): FormConfig;
|
package/dist/core/cms.js
CHANGED
|
@@ -11,6 +11,7 @@ export class CMS {
|
|
|
11
11
|
languages;
|
|
12
12
|
mediaConfig;
|
|
13
13
|
plugins = [];
|
|
14
|
+
apiKeys = [];
|
|
14
15
|
constructor(config) {
|
|
15
16
|
this.config = config;
|
|
16
17
|
this.databaseAdapter = config.db;
|
|
@@ -40,6 +41,7 @@ export class CMS {
|
|
|
40
41
|
};
|
|
41
42
|
});
|
|
42
43
|
this.languages = config.languages || [];
|
|
44
|
+
this.apiKeys = config.apiKeys || [];
|
|
43
45
|
if (config.plugins) {
|
|
44
46
|
this.plugins = config.plugins;
|
|
45
47
|
}
|
|
@@ -161,7 +161,8 @@ export const getEntries = async (options = {}) => {
|
|
|
161
161
|
// Get entries that match the slug/ids filter
|
|
162
162
|
const dbEntries = await getCMS().databaseAdapter.getEntries({
|
|
163
163
|
ids,
|
|
164
|
-
slug
|
|
164
|
+
slug,
|
|
165
|
+
orderBy: options.orderBy
|
|
165
166
|
});
|
|
166
167
|
if (dbEntries.length === 0) {
|
|
167
168
|
return [];
|
|
@@ -6,6 +6,7 @@ export declare const updateEntrySchema: z.ZodObject<{
|
|
|
6
6
|
publishedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
7
7
|
publishedVersionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
8
8
|
publishedBy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
sortOrder: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
9
10
|
}, z.z.core.$strip>;
|
|
10
11
|
export declare const updateEntry: (id: string, data: Partial<DbEntry>) => Promise<DbEntry>;
|
|
11
12
|
export declare const updateEntryVersionSchema: z.ZodObject<{
|
|
@@ -9,7 +9,8 @@ export const updateEntrySchema = z.object({
|
|
|
9
9
|
archivedAt: z.date().nullable().optional(),
|
|
10
10
|
publishedAt: z.date().nullable().optional(),
|
|
11
11
|
publishedVersionId: z.string().uuid().nullable().optional(),
|
|
12
|
-
publishedBy: z.string().nullable().optional()
|
|
12
|
+
publishedBy: z.string().nullable().optional(),
|
|
13
|
+
sortOrder: z.number().int().nullable().optional()
|
|
13
14
|
});
|
|
14
15
|
export const updateEntry = async (id, data) => {
|
|
15
16
|
const filteredDataParse = updateEntrySchema.safeParse(data);
|
|
@@ -33,6 +34,9 @@ export const updateEntry = async (id, data) => {
|
|
|
33
34
|
if (filteredData.publishedBy !== undefined) {
|
|
34
35
|
dataToUpdate.publishedBy = filteredData.publishedBy;
|
|
35
36
|
}
|
|
37
|
+
if (filteredData.sortOrder !== undefined) {
|
|
38
|
+
dataToUpdate.sortOrder = filteredData.sortOrder;
|
|
39
|
+
}
|
|
36
40
|
const updatedEntry = await getCMS().databaseAdapter.updateEntry({
|
|
37
41
|
id,
|
|
38
42
|
data: {
|
|
@@ -200,6 +200,23 @@ export declare const entriesTable: import("drizzle-orm/pg-core/table", { with: {
|
|
|
200
200
|
identity: undefined;
|
|
201
201
|
generated: undefined;
|
|
202
202
|
}, {}, {}>;
|
|
203
|
+
sortOrder: import("drizzle-orm/pg-core", { with: { "resolution-mode": "require" } }).PgColumn<{
|
|
204
|
+
name: "sort_order";
|
|
205
|
+
tableName: "entry";
|
|
206
|
+
dataType: "number";
|
|
207
|
+
columnType: "PgInteger";
|
|
208
|
+
data: number;
|
|
209
|
+
driverParam: string | number;
|
|
210
|
+
notNull: false;
|
|
211
|
+
hasDefault: false;
|
|
212
|
+
isPrimaryKey: false;
|
|
213
|
+
isAutoincrement: false;
|
|
214
|
+
hasRuntimeDefault: false;
|
|
215
|
+
enumValues: undefined;
|
|
216
|
+
baseColumn: never;
|
|
217
|
+
identity: undefined;
|
|
218
|
+
generated: undefined;
|
|
219
|
+
}, {}, {}>;
|
|
203
220
|
};
|
|
204
221
|
dialect: "pg";
|
|
205
222
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
|
|
1
|
+
import { integer, pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
|
|
2
2
|
import { entryVersionsTable } from './entryVersion.js';
|
|
3
3
|
export const entriesTable = pgTable('entry', {
|
|
4
4
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
@@ -12,5 +12,7 @@ export const entriesTable = pgTable('entry', {
|
|
|
12
12
|
// Publish state
|
|
13
13
|
publishedAt: timestamp('published_at'),
|
|
14
14
|
publishedVersionId: uuid('published_version_id').references(() => entryVersionsTable.id, { onDelete: 'set null' }),
|
|
15
|
-
publishedBy: text('published_by')
|
|
15
|
+
publishedBy: text('published_by'),
|
|
16
|
+
// Manual ordering
|
|
17
|
+
sortOrder: integer('sort_order')
|
|
16
18
|
});
|
package/dist/server/auth.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare const auth: import("better-auth", { with: { "resolution-mode": "r
|
|
|
71
71
|
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
|
|
72
72
|
body: {
|
|
73
73
|
userId: string;
|
|
74
|
-
role: "
|
|
74
|
+
role: "admin" | "user" | ("admin" | "user")[];
|
|
75
75
|
};
|
|
76
76
|
} & {
|
|
77
77
|
method?: "POST" | undefined;
|
|
@@ -138,7 +138,7 @@ export declare const auth: import("better-auth", { with: { "resolution-mode": "r
|
|
|
138
138
|
$Infer: {
|
|
139
139
|
body: {
|
|
140
140
|
userId: string;
|
|
141
|
-
role: "
|
|
141
|
+
role: "admin" | "user" | ("admin" | "user")[];
|
|
142
142
|
};
|
|
143
143
|
};
|
|
144
144
|
};
|
|
@@ -236,7 +236,7 @@ export declare const auth: import("better-auth", { with: { "resolution-mode": "r
|
|
|
236
236
|
email: string;
|
|
237
237
|
password: string;
|
|
238
238
|
name: string;
|
|
239
|
-
role?: "
|
|
239
|
+
role?: "admin" | "user" | ("admin" | "user")[] | undefined;
|
|
240
240
|
data?: Record<string, any>;
|
|
241
241
|
};
|
|
242
242
|
} & {
|
|
@@ -302,7 +302,7 @@ export declare const auth: import("better-auth", { with: { "resolution-mode": "r
|
|
|
302
302
|
email: string;
|
|
303
303
|
password: string;
|
|
304
304
|
name: string;
|
|
305
|
-
role?: "
|
|
305
|
+
role?: "admin" | "user" | ("admin" | "user")[] | undefined;
|
|
306
306
|
data?: Record<string, any>;
|
|
307
307
|
};
|
|
308
308
|
};
|
|
@@ -1184,7 +1184,7 @@ export declare const auth: import("better-auth", { with: { "resolution-mode": "r
|
|
|
1184
1184
|
permission?: never;
|
|
1185
1185
|
}) & {
|
|
1186
1186
|
userId?: string;
|
|
1187
|
-
role?: "
|
|
1187
|
+
role?: "admin" | "user" | undefined;
|
|
1188
1188
|
};
|
|
1189
1189
|
} & {
|
|
1190
1190
|
method?: "POST" | undefined;
|
|
@@ -1287,7 +1287,7 @@ export declare const auth: import("better-auth", { with: { "resolution-mode": "r
|
|
|
1287
1287
|
permission?: never;
|
|
1288
1288
|
}) & {
|
|
1289
1289
|
userId?: string;
|
|
1290
|
-
role?: "
|
|
1290
|
+
role?: "admin" | "user" | undefined;
|
|
1291
1291
|
};
|
|
1292
1292
|
};
|
|
1293
1293
|
};
|