@xleddyl/nuxt-cms 0.1.23 → 0.1.24

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.
Files changed (69) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +16 -3
  3. package/dist/runtime/app/components/cms/BlocksField.vue +2 -9
  4. package/dist/runtime/app/components/cms/Button.vue +4 -2
  5. package/dist/runtime/app/components/cms/ConfirmModal.vue +5 -14
  6. package/dist/runtime/app/components/cms/Drawer.d.vue.ts +30 -0
  7. package/dist/runtime/app/components/cms/Drawer.vue +65 -0
  8. package/dist/runtime/app/components/cms/Drawer.vue.d.ts +30 -0
  9. package/dist/runtime/app/components/cms/DropdownMenu.d.vue.ts +0 -3
  10. package/dist/runtime/app/components/cms/DropdownMenu.vue +2 -7
  11. package/dist/runtime/app/components/cms/DropdownMenu.vue.d.ts +0 -3
  12. package/dist/runtime/app/components/cms/EmptyState.d.vue.ts +1 -0
  13. package/dist/runtime/app/components/cms/EmptyState.vue +6 -7
  14. package/dist/runtime/app/components/cms/EmptyState.vue.d.ts +1 -0
  15. package/dist/runtime/app/components/cms/EntryDrawer.d.vue.ts +21 -0
  16. package/dist/runtime/app/components/cms/EntryDrawer.vue +193 -0
  17. package/dist/runtime/app/components/cms/EntryDrawer.vue.d.ts +21 -0
  18. package/dist/runtime/app/components/cms/EntryForm.vue +19 -7
  19. package/dist/runtime/app/components/cms/FieldInput.d.vue.ts +1 -0
  20. package/dist/runtime/app/components/cms/FieldInput.vue +13 -27
  21. package/dist/runtime/app/components/cms/FieldInput.vue.d.ts +1 -0
  22. package/dist/runtime/app/components/cms/Form.vue +1 -1
  23. package/dist/runtime/app/components/cms/FormField.d.vue.ts +4 -5
  24. package/dist/runtime/app/components/cms/FormField.vue +9 -7
  25. package/dist/runtime/app/components/cms/FormField.vue.d.ts +4 -5
  26. package/dist/runtime/app/components/cms/JsonField.vue +3 -4
  27. package/dist/runtime/app/components/cms/LocaleSwitch.d.vue.ts +14 -0
  28. package/dist/runtime/app/components/cms/LocaleSwitch.vue +29 -0
  29. package/dist/runtime/app/components/cms/LocaleSwitch.vue.d.ts +14 -0
  30. package/dist/runtime/app/components/cms/MediaField.vue +7 -17
  31. package/dist/runtime/app/components/cms/MediaGallery.vue +48 -78
  32. package/dist/runtime/app/components/cms/MediaThumb.d.vue.ts +6 -0
  33. package/dist/runtime/app/components/cms/MediaThumb.vue +40 -0
  34. package/dist/runtime/app/components/cms/MediaThumb.vue.d.ts +6 -0
  35. package/dist/runtime/app/components/cms/Modal.d.vue.ts +1 -4
  36. package/dist/runtime/app/components/cms/Modal.vue +8 -7
  37. package/dist/runtime/app/components/cms/Modal.vue.d.ts +1 -4
  38. package/dist/runtime/app/components/cms/PageHeader.d.vue.ts +1 -1
  39. package/dist/runtime/app/components/cms/PageHeader.vue +6 -6
  40. package/dist/runtime/app/components/cms/PageHeader.vue.d.ts +1 -1
  41. package/dist/runtime/app/components/cms/RelationField.vue +0 -4
  42. package/dist/runtime/app/components/cms/SelectMenu.vue +23 -3
  43. package/dist/runtime/app/components/cms/SlugField.vue +1 -2
  44. package/dist/runtime/app/components/cms/Spinner.d.vue.ts +3 -0
  45. package/dist/runtime/app/components/cms/Spinner.vue +5 -0
  46. package/dist/runtime/app/components/cms/Spinner.vue.d.ts +3 -0
  47. package/dist/runtime/app/components/cms/StatusBadge.d.vue.ts +6 -0
  48. package/dist/runtime/app/components/cms/StatusBadge.vue +11 -0
  49. package/dist/runtime/app/components/cms/StatusBadge.vue.d.ts +6 -0
  50. package/dist/runtime/app/components/cms/Table.d.vue.ts +3 -6
  51. package/dist/runtime/app/components/cms/Table.vue +72 -27
  52. package/dist/runtime/app/components/cms/Table.vue.d.ts +3 -6
  53. package/dist/runtime/app/components/cms/Toaster.vue +4 -4
  54. package/dist/runtime/app/components/cms/TranslatableField.d.vue.ts +1 -0
  55. package/dist/runtime/app/components/cms/TranslatableField.vue +7 -44
  56. package/dist/runtime/app/components/cms/TranslatableField.vue.d.ts +1 -0
  57. package/dist/runtime/app/layouts/cms-admin.vue +10 -20
  58. package/dist/runtime/app/pages/admin-collection.vue +130 -103
  59. package/dist/runtime/app/pages/admin-entry.vue +6 -24
  60. package/dist/runtime/app/pages/admin-login.vue +12 -31
  61. package/dist/runtime/app/pages/admin-media.vue +8 -2
  62. package/dist/runtime/app/utils/ui.d.ts +0 -7
  63. package/dist/runtime/app/utils/ui.js +0 -5
  64. package/dist/runtime/assets/main.css +1 -1
  65. package/dist/runtime/server/api/collection.get.js +8 -3
  66. package/dist/runtime/server/utils/relations.d.ts +1 -0
  67. package/dist/runtime/server/utils/relations.js +25 -0
  68. package/dist/runtime/shared/index.d.ts +10 -3
  69. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  import { asc, eq, inArray } from "drizzle-orm";
2
2
  import { createError } from "h3";
3
+ import cmsConfig from "#cms-config";
3
4
  import { useDb } from "#cms-db";
4
5
  import * as cmsTables from "#cms-tables";
5
6
  import { resolveTable, tableColumns } from "./registry.js";
@@ -57,6 +58,30 @@ export async function saveManyToMany(db, name, sourceId, lists) {
57
58
  }
58
59
  }
59
60
  }
61
+ export async function relationTitles(db, entry, rows) {
62
+ const config = cmsConfig;
63
+ const titles = {};
64
+ for (const [key, field] of Object.entries(entry.fields)) {
65
+ if (field.type !== "relation" || !field.to) continue;
66
+ const targetEntry = config[field.to];
67
+ const target = resolveTable(field.to);
68
+ if (!targetEntry?.titleField || !target) continue;
69
+ const ids = /* @__PURE__ */ new Set();
70
+ for (const row of rows) {
71
+ const value = row[key];
72
+ for (const id of Array.isArray(value) ? value : [value]) {
73
+ if (id != null) ids.add(String(id));
74
+ }
75
+ }
76
+ if (!ids.size) continue;
77
+ const columns = tableColumns(target);
78
+ const titleColumn = columns[targetEntry.titleField];
79
+ if (!titleColumn) continue;
80
+ const found = await db.select({ id: columns.id, title: titleColumn }).from(target).where(inArray(columns.id, [...ids]));
81
+ titles[key] = Object.fromEntries(found.map((row) => [row.id, row.title]));
82
+ }
83
+ return titles;
84
+ }
60
85
  export async function attachManyToMany(db, name, entry, rows) {
61
86
  const keys = manyToManyKeys(entry);
62
87
  const ids = rows.map((row) => row.id).filter((id) => id != null);
@@ -121,14 +121,21 @@ export interface BlocksFieldInput extends FieldInputBase {
121
121
  blocks: Record<string, BlockInput>;
122
122
  }
123
123
  export type CmsFieldInput = TextFieldInput | RichtextFieldInput | NumberFieldInput | BooleanFieldInput | DateFieldInput | EmailFieldInput | SlugFieldInput | SelectFieldInput | JsonFieldInput | MediaFieldInput | RelationFieldInput | BlocksFieldInput;
124
- export interface CmsEntryInput {
124
+ interface CmsEntryInputBase {
125
125
  id: string;
126
126
  label: string;
127
- kind: 'collection' | 'single';
128
- titleField?: string;
129
127
  drafts?: boolean;
130
128
  fields: Record<string, CmsFieldInput>;
131
129
  }
130
+ export interface CmsCollectionInput extends CmsEntryInputBase {
131
+ kind: 'collection';
132
+ titleField: string;
133
+ }
134
+ export interface CmsSingleInput extends CmsEntryInputBase {
135
+ kind: 'single';
136
+ titleField?: never;
137
+ }
138
+ export type CmsEntryInput = CmsCollectionInput | CmsSingleInput;
132
139
  export type CmsConfigInput = Record<string, CmsEntryInput>;
133
140
  export declare function defineCmsConfig<T extends CmsConfigInput>(config: T): T;
134
141
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Lightweight CMS that ships with your Nuxt app: runs on the Nitro server, content types defined in code, /cms admin panel, GraphQL API, SQLite or Postgres. No external CMS needed!",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",