@kurbo/dkit 0.5.0 → 0.5.1

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 (96) hide show
  1. package/dist/bin.js +119 -26
  2. package/dist/bin.js.map +1 -1
  3. package/package.json +1 -1
  4. package/vendor/registry/blocks/blog-detail/ui/minimal/next/blog-detail.tsx +0 -1
  5. package/vendor/registry/blocks/blog-detail/ui/shadcn/next/blog-detail.tsx +0 -1
  6. package/vendor/registry/blocks/blog-list/ui/minimal/next/blog-list.tsx +0 -1
  7. package/vendor/registry/blocks/blog-list/ui/shadcn/next/blog-list.tsx +0 -1
  8. package/vendor/registry/blocks/blog-list-cards/ui/minimal/next/blog-list-cards.tsx +0 -1
  9. package/vendor/registry/blocks/blog-list-cards/ui/shadcn/next/blog-list-cards.tsx +0 -1
  10. package/vendor/registry/blocks/booking-form-ui/ui/minimal/next/booking-form.tsx +0 -1
  11. package/vendor/registry/blocks/booking-form-ui/ui/shadcn/next/booking-form.tsx +0 -1
  12. package/vendor/registry/blocks/contact-form-ui/ui/minimal/next/contact-form.tsx +0 -1
  13. package/vendor/registry/blocks/contact-form-ui/ui/shadcn/next/contact-form.tsx +0 -1
  14. package/vendor/registry/blocks/faq-list/ui/minimal/next/faq-list.tsx +0 -1
  15. package/vendor/registry/blocks/faq-list/ui/shadcn/next/faq-list.tsx +0 -1
  16. package/vendor/registry/blocks/page-detail/ui/minimal/next/page-detail.tsx +0 -1
  17. package/vendor/registry/blocks/page-detail/ui/shadcn/next/page-detail.tsx +0 -1
  18. package/vendor/registry/blocks/project-detail/ui/minimal/next/project-detail.tsx +0 -1
  19. package/vendor/registry/blocks/project-detail/ui/shadcn/next/project-detail.tsx +0 -1
  20. package/vendor/registry/blocks/project-list/ui/minimal/next/project-list.tsx +0 -1
  21. package/vendor/registry/blocks/project-list/ui/shadcn/next/project-list.tsx +0 -1
  22. package/vendor/registry/blocks/project-list-cards/ui/minimal/next/project-list-cards.tsx +0 -1
  23. package/vendor/registry/blocks/project-list-cards/ui/shadcn/next/project-list-cards.tsx +0 -1
  24. package/vendor/registry/blocks/projects-carousel/ui/minimal/next/projects-carousel-client.tsx +0 -4
  25. package/vendor/registry/blocks/projects-carousel/ui/minimal/next/projects-carousel.tsx +0 -1
  26. package/vendor/registry/blocks/projects-carousel/ui/shadcn/next/projects-carousel-client.tsx +0 -1
  27. package/vendor/registry/blocks/projects-carousel/ui/shadcn/next/projects-carousel.tsx +0 -1
  28. package/vendor/registry/blocks/service-detail/ui/minimal/next/service-detail.tsx +0 -1
  29. package/vendor/registry/blocks/service-detail/ui/shadcn/next/service-detail.tsx +0 -1
  30. package/vendor/registry/blocks/service-list/ui/minimal/next/service-list.tsx +0 -1
  31. package/vendor/registry/blocks/service-list/ui/shadcn/next/service-list.tsx +0 -1
  32. package/vendor/registry/blocks/service-list-cards/ui/minimal/next/service-list-cards.tsx +0 -1
  33. package/vendor/registry/blocks/service-list-cards/ui/shadcn/next/service-list-cards.tsx +0 -1
  34. package/vendor/registry/blocks/social-links/ui/minimal/next/social-links.tsx +0 -1
  35. package/vendor/registry/blocks/social-links/ui/shadcn/next/social-links.tsx +0 -1
  36. package/vendor/registry/blocks/team-detail/ui/minimal/next/team-detail.tsx +0 -1
  37. package/vendor/registry/blocks/team-detail/ui/shadcn/next/team-detail.tsx +0 -1
  38. package/vendor/registry/blocks/team-list/ui/minimal/next/team-list.tsx +0 -1
  39. package/vendor/registry/blocks/team-list/ui/shadcn/next/team-list.tsx +0 -1
  40. package/vendor/registry/blocks/team-list-cards/ui/minimal/next/team-list-cards.tsx +0 -1
  41. package/vendor/registry/blocks/team-list-cards/ui/shadcn/next/team-list-cards.tsx +0 -1
  42. package/vendor/registry/blocks/testimonials-carousel/ui/minimal/next/testimonials-carousel-client.tsx +0 -4
  43. package/vendor/registry/blocks/testimonials-carousel/ui/minimal/next/testimonials-carousel.tsx +0 -1
  44. package/vendor/registry/blocks/testimonials-carousel/ui/shadcn/next/testimonials-carousel-client.tsx +0 -1
  45. package/vendor/registry/blocks/testimonials-carousel/ui/shadcn/next/testimonials-carousel.tsx +0 -1
  46. package/vendor/registry/blocks/testimonials-list/ui/minimal/next/testimonials-list.tsx +0 -1
  47. package/vendor/registry/blocks/testimonials-list/ui/shadcn/next/testimonials-list.tsx +0 -1
  48. package/vendor/registry/blocks/testimonials-list-cards/ui/minimal/next/testimonials-list-cards.tsx +0 -1
  49. package/vendor/registry/blocks/testimonials-list-cards/ui/shadcn/next/testimonials-list-cards.tsx +0 -1
  50. package/vendor/registry/modules/blog/lib.multilocale.ts +124 -129
  51. package/vendor/registry/modules/blog/lib.ts +12 -9
  52. package/vendor/registry/modules/blog/services/seed.json +1 -1
  53. package/vendor/registry/modules/blog/services/seed.multilocale.json +1 -1
  54. package/vendor/registry/modules/blog/types.multilocale.ts +41 -12
  55. package/vendor/registry/modules/blog/types.ts +8 -6
  56. package/vendor/registry/modules/faq/lib.multilocale.ts +30 -30
  57. package/vendor/registry/modules/faq/lib.ts +4 -5
  58. package/vendor/registry/modules/faq/types.multilocale.ts +13 -2
  59. package/vendor/registry/modules/faq/types.ts +4 -2
  60. package/vendor/registry/modules/navigation/lib.multilocale.ts +207 -76
  61. package/vendor/registry/modules/navigation/lib.ts +18 -17
  62. package/vendor/registry/modules/navigation/types.multilocale.ts +24 -4
  63. package/vendor/registry/modules/navigation/types.ts +6 -4
  64. package/vendor/registry/modules/pages/lib.multilocale.ts +34 -39
  65. package/vendor/registry/modules/pages/lib.ts +4 -3
  66. package/vendor/registry/modules/pages/types.multilocale.ts +14 -3
  67. package/vendor/registry/modules/pages/types.ts +5 -3
  68. package/vendor/registry/modules/projects/lib.multilocale.ts +149 -65
  69. package/vendor/registry/modules/projects/lib.ts +6 -6
  70. package/vendor/registry/modules/projects/services/seed.json +2 -2
  71. package/vendor/registry/modules/projects/services/seed.multilocale.json +2 -2
  72. package/vendor/registry/modules/projects/types.multilocale.ts +15 -3
  73. package/vendor/registry/modules/projects/types.ts +5 -3
  74. package/vendor/registry/modules/services/lib.multilocale.ts +143 -63
  75. package/vendor/registry/modules/services/lib.ts +6 -6
  76. package/vendor/registry/modules/services/services/seed.json +4 -4
  77. package/vendor/registry/modules/services/services/seed.multilocale.json +2 -2
  78. package/vendor/registry/modules/services/types.multilocale.ts +13 -3
  79. package/vendor/registry/modules/services/types.ts +5 -3
  80. package/vendor/registry/modules/settings/lib.multilocale.ts +159 -57
  81. package/vendor/registry/modules/settings/types.multilocale.ts +15 -0
  82. package/vendor/registry/modules/settings/types.ts +2 -2
  83. package/vendor/registry/modules/team/lib.multilocale.ts +116 -49
  84. package/vendor/registry/modules/team/lib.ts +4 -3
  85. package/vendor/registry/modules/team/services/seed.json +4 -4
  86. package/vendor/registry/modules/team/services/seed.multilocale.json +2 -2
  87. package/vendor/registry/modules/team/types.multilocale.ts +16 -3
  88. package/vendor/registry/modules/team/types.ts +5 -3
  89. package/vendor/registry/modules/testimonials/lib.multilocale.ts +82 -50
  90. package/vendor/registry/modules/testimonials/services/seed.json +4 -4
  91. package/vendor/registry/modules/testimonials/services/seed.multilocale.json +2 -2
  92. package/vendor/registry/modules/testimonials/types.multilocale.ts +14 -2
  93. package/vendor/registry/modules/testimonials/types.ts +4 -2
  94. package/vendor/registry/shared/helpers.ts +9 -3
  95. package/vendor/registry/shared/i18n.ts +84 -12
  96. package/vendor/registry/shared/prose.css +1 -1
@@ -1,3 +1,5 @@
1
+ type DkitSortField<T extends string> = T | `-${T}`;
2
+
1
3
  export type DirectusFileRef = {
2
4
  id: string;
3
5
  };
@@ -17,11 +19,11 @@ export type TeamMember = {
17
19
  /** Shared list/query options for team member fetches. */
18
20
  export type GetTeamMembersOptions = {
19
21
  /** Directus status filter. Default `"published"`. Pass `null` to skip. */
20
- status?: string | null;
22
+ status?: TeamMember["status"] | null;
21
23
  limit?: number;
22
- sort?: string[];
24
+ sort?: Array<DkitSortField<"sort" | "name" | "id" | "status" | "slug">>;
23
25
  };
24
26
 
25
27
  export type GetTeamMemberBySlugOptions = {
26
- status?: string | null;
28
+ status?: TeamMember["status"] | null;
27
29
  };
@@ -3,40 +3,58 @@ import {
3
3
  directusFileId,
4
4
  dkitQueryFailed,
5
5
  getDirectus,
6
- readItem,
7
6
  readItems,
8
7
  } from "@/lib/dkit/client";
9
8
  import { collections } from "@/lib/dkit/config";
10
9
  import { queryLimit, statusFilter } from "@/lib/dkit/helpers";
11
10
  import {
12
- isUsableTranslation,
13
- pickTranslation,
14
11
  requireLocaleTranslation,
15
12
  resolveLocale,
16
13
  translationsDeepFilter,
14
+ withLocale,
17
15
  } from "@/lib/dkit/i18n";
18
- import type { GetTestimonialsOptions, Testimonial, TestimonialTranslation } from "./types.multilocale";
16
+ import type {
17
+ GetTestimonialsOptions,
18
+ Testimonial,
19
+ TestimonialRow,
20
+ } from "./types.multilocale";
19
21
 
20
- export type { DirectusFileRef, GetTestimonialsOptions, Testimonial, TestimonialTranslation } from "./types.multilocale";
22
+ export type {
23
+ DirectusFileRef,
24
+ GetTestimonialsOptions,
25
+ Testimonial,
26
+ TestimonialRow,
27
+ TestimonialTranslation,
28
+ } from "./types.multilocale";
21
29
 
22
- function flattenTestimonial(row: Record<string, unknown>, locale: string): Testimonial | null {
23
- const trans = pickTranslation(row.translations as TestimonialTranslation[] | undefined, locale);
24
- if (!isUsableTranslation(trans, ["quote"])) return null;
25
-
26
- return {
27
- id: row.id as string,
28
- status: row.status as Testimonial["status"],
29
- quote: trans!.quote!,
30
- author_name: row.author_name as string,
31
- author_role: trans?.author_role ?? null,
32
- company: (row.company as string | null) ?? null,
33
- avatar: row.avatar as Testimonial["avatar"],
34
- sort: (row.sort as number | null) ?? null,
35
- };
30
+ function flattenTestimonial(
31
+ row: TestimonialRow,
32
+ locale: string,
33
+ ): Testimonial | null {
34
+ return withLocale(
35
+ row,
36
+ locale,
37
+ (r, t) => ({
38
+ id: r.id,
39
+ status: r.status,
40
+ quote: t.quote,
41
+ author_name: r.author_name,
42
+ author_role: t.author_role ?? null,
43
+ company: r.company ?? null,
44
+ avatar: r.avatar,
45
+ sort: r.sort ?? null,
46
+ }),
47
+ { required: ["quote"] },
48
+ );
36
49
  }
37
50
 
38
51
  const TESTIMONIAL_FIELDS = [
39
- "id", "status", "author_name", "company", "avatar", "sort",
52
+ "id",
53
+ "status",
54
+ "author_name",
55
+ "company",
56
+ "avatar",
57
+ "sort",
40
58
  { translations: ["id", "languages_code", "quote", "author_role"] },
41
59
  ] as const;
42
60
 
@@ -45,49 +63,63 @@ export function testimonialAvatarUrl(testimonial: Testimonial): string | null {
45
63
  return id ? directusAssetUrl(id) : null;
46
64
  }
47
65
 
48
- export async function getTestimonials(options: GetTestimonialsOptions = {}): Promise<Testimonial[]> {
66
+ export async function getTestimonials(
67
+ options: GetTestimonialsOptions = {},
68
+ ): Promise<Testimonial[]> {
49
69
  const client = getDirectus();
50
70
  if (!client) return [];
51
- if (!collections.testimonials) { dkitQueryFailed('collections.testimonials missing — re-run `dkit add testimonials`'); return []; }
71
+ if (!collections.testimonials) {
72
+ dkitQueryFailed(
73
+ "collections.testimonials missing — re-run `dkit add testimonials`",
74
+ );
75
+ return [];
76
+ }
52
77
  const locale = await resolveLocale(options.locale);
53
78
  const status = statusFilter(options.status);
54
- const and: Record<string, unknown>[] = [
55
- requireLocaleTranslation(locale, ["quote"]),
56
- ];
57
- if (status) and.unshift(status);
79
+ const filter = status
80
+ ? { _and: [status, requireLocaleTranslation(locale, ["quote"])] }
81
+ : requireLocaleTranslation(locale, ["quote"]);
58
82
  const limit = queryLimit(options.limit);
59
83
  try {
60
- const rows = await client.request(readItems(collections.testimonials, {
61
- filter: { _and: and },
62
- deep: translationsDeepFilter(locale),
63
- fields: [...TESTIMONIAL_FIELDS],
64
- sort: options.sort ?? ["sort", "author_name"],
65
- ...(limit !== undefined ? { limit } : {}),
66
- }));
67
- return (rows as Record<string, unknown>[])
84
+ const rows = await client.request(
85
+ readItems(collections.testimonials, {
86
+ filter,
87
+ deep: translationsDeepFilter(locale),
88
+ fields: [...TESTIMONIAL_FIELDS],
89
+ sort: options.sort ?? ["sort", "author_name"],
90
+ ...(limit !== undefined ? { limit } : {}),
91
+ }),
92
+ );
93
+ return (rows as TestimonialRow[])
68
94
  .map((r) => flattenTestimonial(r, locale))
69
95
  .filter((t): t is Testimonial => t != null);
70
- } catch (err) { dkitQueryFailed(`getTestimonials failed`, err); return []; }
96
+ } catch (err) {
97
+ dkitQueryFailed(`getTestimonials failed`, err);
98
+ return [];
99
+ }
71
100
  }
72
101
 
73
- export async function getTestimonialById(id: string, options: { locale?: string } = {}): Promise<Testimonial | null> {
102
+ export async function getTestimonialById(
103
+ id: string,
104
+ options: { locale?: string } = {},
105
+ ): Promise<Testimonial | null> {
74
106
  const client = getDirectus();
75
107
  if (!client) return null;
76
108
  if (!collections.testimonials) return null;
77
109
  const locale = await resolveLocale(options.locale);
78
110
  try {
79
- const rows = await client.request(readItems(collections.testimonials, {
80
- filter: {
81
- _and: [
82
- { id: { _eq: id } },
83
- requireLocaleTranslation(locale, ["quote"]),
84
- ],
85
- },
86
- deep: translationsDeepFilter(locale),
87
- fields: [...TESTIMONIAL_FIELDS],
88
- limit: 1,
89
- }));
90
- const row = (rows as Record<string, unknown>[])[0];
91
- return row ? flattenTestimonial(row as Record<string, unknown>, locale) : null;
92
- } catch (err) { dkitQueryFailed(`getTestimonialById(${id}) failed`, err); return null; }
111
+ const rows = await client.request(
112
+ readItems(collections.testimonials, {
113
+ filter: { _and: [{ id: { _eq: id } }, requireLocaleTranslation(locale, ["quote"])] },
114
+ deep: translationsDeepFilter(locale),
115
+ fields: [...TESTIMONIAL_FIELDS],
116
+ limit: 1,
117
+ }),
118
+ );
119
+ const row = (rows as TestimonialRow[])[0];
120
+ return row ? flattenTestimonial(row, locale) : null;
121
+ } catch (err) {
122
+ dkitQueryFailed(`getTestimonialById(${id}) failed`, err);
123
+ return null;
124
+ }
93
125
  }
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "files": [
3
3
  {
4
- "id": "m1000000-0000-4000-8000-000000000001",
4
+ "id": "b1000000-0000-4000-8000-000000000001",
5
5
  "filename_download": "sample-author-avatar.jpg",
6
6
  "title": "Sample avatar — Sample Author (Unsplash)",
7
7
  "type": "image/jpeg",
8
8
  "path": "assets/sample-author-avatar.jpg"
9
9
  },
10
10
  {
11
- "id": "m1000000-0000-4000-8000-000000000002",
11
+ "id": "b1000000-0000-4000-8000-000000000002",
12
12
  "filename_download": "jane-doe-avatar.jpg",
13
13
  "title": "Sample avatar — Jane Doe (Unsplash)",
14
14
  "type": "image/jpeg",
@@ -24,7 +24,7 @@
24
24
  "author_name": "Sample Author",
25
25
  "author_role": "Head of Product",
26
26
  "company": "Acme Corp",
27
- "avatar": "m1000000-0000-4000-8000-000000000001",
27
+ "avatar": "b1000000-0000-4000-8000-000000000001",
28
28
  "sort": 1
29
29
  },
30
30
  {
@@ -34,7 +34,7 @@
34
34
  "author_name": "Jane Doe",
35
35
  "author_role": "Engineering Lead",
36
36
  "company": "Globex Inc",
37
- "avatar": "m1000000-0000-4000-8000-000000000002",
37
+ "avatar": "b1000000-0000-4000-8000-000000000002",
38
38
  "sort": 2
39
39
  },
40
40
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": [
3
3
  {
4
- "id": "m1000000-0000-4000-8000-000000000001",
4
+ "id": "b1000000-0000-4000-8000-000000000001",
5
5
  "filename_download": "sample-author-avatar.jpg",
6
6
  "title": "Sample avatar — Sample Author (Unsplash)",
7
7
  "type": "image/jpeg",
@@ -15,7 +15,7 @@
15
15
  "status": "published",
16
16
  "author_name": "Jane Doe",
17
17
  "company": "Acme Inc.",
18
- "avatar": "m1000000-0000-4000-8000-000000000001",
18
+ "avatar": "b1000000-0000-4000-8000-000000000001",
19
19
  "sort": 1,
20
20
  "translations": [
21
21
  {
@@ -1,3 +1,5 @@
1
+ type DkitSortField<T extends string> = T | `-${T}`;
2
+
1
3
  export type DirectusFileRef = { id: string };
2
4
 
3
5
  export type TestimonialTranslation = {
@@ -8,6 +10,16 @@ export type TestimonialTranslation = {
8
10
  author_role?: string | null;
9
11
  };
10
12
 
13
+ export type TestimonialRow = {
14
+ id: string;
15
+ status: "published" | "draft";
16
+ author_name: string;
17
+ company?: string | null;
18
+ avatar?: string | DirectusFileRef | null;
19
+ sort?: number | null;
20
+ translations?: TestimonialTranslation[] | null;
21
+ };
22
+
11
23
  export type Testimonial = {
12
24
  id: string;
13
25
  status: "published" | "draft";
@@ -20,8 +32,8 @@ export type Testimonial = {
20
32
  };
21
33
 
22
34
  export type GetTestimonialsOptions = {
23
- status?: string | null;
35
+ status?: Testimonial["status"] | null;
24
36
  limit?: number;
25
- sort?: string[];
37
+ sort?: Array<DkitSortField<"sort" | "id" | "status" | "author_name">>;
26
38
  locale?: string;
27
39
  };
@@ -1,3 +1,5 @@
1
+ type DkitSortField<T extends string> = T | `-${T}`;
2
+
1
3
  export type DirectusFileRef = {
2
4
  id: string;
3
5
  };
@@ -16,7 +18,7 @@ export type Testimonial = {
16
18
  /** Shared list/query options for testimonial fetches. */
17
19
  export type GetTestimonialsOptions = {
18
20
  /** Directus status filter. Default `"published"`. Pass `null` to skip. */
19
- status?: string | null;
21
+ status?: Testimonial["status"] | null;
20
22
  limit?: number;
21
- sort?: string[];
23
+ sort?: Array<DkitSortField<"sort" | "id" | "status" | "author_name">>;
22
24
  };
@@ -4,10 +4,16 @@
4
4
  * Safe to edit.
5
5
  */
6
6
 
7
- /** Default status=published; pass `status: null` to skip the filter. */
8
- export function statusFilter(status: string | null | undefined) {
7
+ /**
8
+ * Default status=published; pass `status: null` to skip the filter.
9
+ * Generic so `_eq` keeps the collection's status union (not widened to `string`).
10
+ */
11
+ export function statusFilter<S extends string = "published">(
12
+ status?: S | null,
13
+ fallback: S = "published" as S,
14
+ ): { status: { _eq: S } } | undefined {
9
15
  if (status === null) return undefined;
10
- return { status: { _eq: status ?? "published" } };
16
+ return { status: { _eq: status ?? fallback } };
11
17
  }
12
18
 
13
19
  /** Directus rejects `limit=undefined` — only send a finite number. */
@@ -6,17 +6,28 @@
6
6
  import { defaultLocale } from "@/lib/dkit/config";
7
7
  import { getRequestLocale } from "@/lib/dkit/locale";
8
8
 
9
+ export type TranslationCode = string | { code?: string };
10
+
11
+ export type TranslationLike = {
12
+ languages_code?: TranslationCode | null;
13
+ };
14
+
15
+ export type WithTranslations<T extends TranslationLike> = {
16
+ translations?: T[] | null;
17
+ };
18
+
9
19
  export function translationCode(
10
- languages_code: string | { code?: string } | null | undefined,
20
+ languages_code: TranslationCode | null | undefined,
11
21
  ): string | undefined {
12
22
  if (typeof languages_code === "string") return languages_code;
13
23
  return languages_code?.code;
14
24
  }
15
25
 
16
26
  /** Exact locale only — never fall back to another language's row. */
17
- export function pickTranslation<
18
- T extends { languages_code?: string | { code?: string } },
19
- >(rows: T[] | null | undefined, locale: string): T | undefined {
27
+ export function pickTranslation<T extends TranslationLike>(
28
+ rows: T[] | null | undefined,
29
+ locale: string,
30
+ ): T | undefined {
20
31
  if (!Array.isArray(rows) || rows.length === 0) return undefined;
21
32
  return rows.find((r) => translationCode(r.languages_code) === locale);
22
33
  }
@@ -38,11 +49,15 @@ export async function resolveLocale(
38
49
  /**
39
50
  * Filter: item must have a translation for `locale` with every listed field
40
51
  * non-empty. Defaults to title + slug (posts, pages, projects, services).
52
+ *
53
+ * Return is intentionally loose — dynamic translation field names do not fit
54
+ * `QueryFilter` literals from `@directus/sdk`.
41
55
  */
42
56
  export function requireLocaleTranslation(
43
57
  locale: string,
44
58
  fields: string[] = ["title", "slug"],
45
- ) {
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ ): any {
46
61
  return {
47
62
  translations: {
48
63
  _and: [
@@ -53,22 +68,79 @@ export function requireLocaleTranslation(
53
68
  };
54
69
  }
55
70
 
56
- /** Deep query: only load translation rows for this locale. */
57
- export function translationsDeepFilter(locale: string) {
71
+ /**
72
+ * Deep query: only load translation rows for this locale.
73
+ * Use as `deep: translationsDeepFilter(locale)` on readItems.
74
+ */
75
+ export function translationsDeepFilter(
76
+ locale: string,
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ ): any {
58
79
  return {
59
80
  translations: { _filter: { languages_code: { _eq: locale } } },
60
- } as Record<string, unknown>;
81
+ };
61
82
  }
62
83
 
63
84
  /**
64
85
  * True when every listed field is a non-empty string on the translation row.
65
86
  * Defaults to title + slug.
66
87
  */
67
- export function isUsableTranslation(
68
- trans: object | null | undefined,
69
- fields: string[] = ["title", "slug"],
70
- ): boolean {
88
+ export function isUsableTranslation<T extends object>(
89
+ trans: T | null | undefined,
90
+ fields: readonly string[] = ["title", "slug"],
91
+ ): trans is T {
71
92
  if (!trans) return false;
72
93
  const row = trans as Record<string, unknown>;
73
94
  return fields.every((f) => Boolean(String(row[f] ?? "").trim()));
74
95
  }
96
+
97
+ type WithLocaleRequiredOptions = {
98
+ required: readonly string[];
99
+ fallbackLocale?: string;
100
+ };
101
+
102
+ type WithLocaleOptionalOptions = {
103
+ required?: undefined;
104
+ fallbackLocale?: string;
105
+ };
106
+
107
+ type TranslationOf<TRow> = TRow extends {
108
+ translations?: Array<infer T> | null;
109
+ }
110
+ ? Extract<T, TranslationLike>
111
+ : TranslationLike;
112
+
113
+ /**
114
+ * Pick a translation for `locale` (optional fallback) and map to a public shape.
115
+ * When `required` is set, missing/empty fields → `null` and `map` receives a defined translation.
116
+ */
117
+ export function withLocale<TRow extends WithTranslations<TranslationLike>, TOut>(
118
+ row: TRow,
119
+ locale: string,
120
+ map: (row: TRow, trans: TranslationOf<TRow>) => TOut | null,
121
+ options: WithLocaleRequiredOptions,
122
+ ): TOut | null;
123
+ export function withLocale<TRow extends WithTranslations<TranslationLike>, TOut>(
124
+ row: TRow,
125
+ locale: string,
126
+ map: (row: TRow, trans: TranslationOf<TRow> | undefined) => TOut | null,
127
+ options?: WithLocaleOptionalOptions,
128
+ ): TOut | null;
129
+ /** @internal overload impl — keep loose so required/optional map signatures both type-check */
130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
+ export function withLocale(
132
+ row: any,
133
+ locale: string,
134
+ map: any,
135
+ options?: { required?: readonly string[]; fallbackLocale?: string },
136
+ ): any {
137
+ let trans = pickTranslation(row.translations, locale);
138
+ if (!trans && options?.fallbackLocale) {
139
+ trans = pickTranslation(row.translations, options.fallbackLocale);
140
+ }
141
+ if (options?.required) {
142
+ if (!isUsableTranslation(trans, options.required)) return null;
143
+ return map(row, trans);
144
+ }
145
+ return map(row, trans);
146
+ }
@@ -2,7 +2,7 @@
2
2
  * Shared rich-text styles for dkit content modules (blog, pages, page-builder, …).
3
3
  * Import once in your app CSS. Override tokens below to match your brand.
4
4
  *
5
- * Uses shadcn / shadcn-vue CSS variables when present
5
+ * Uses shadcn CSS variables when present
6
6
  * (--foreground, --muted-foreground, --primary, --border, --muted, --radius)
7
7
  * with sensible fallbacks for bare projects.
8
8
  *