@kurbo/dkit 0.4.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/README.md +24 -0
- package/dist/bin.js +8066 -0
- package/dist/bin.js.map +1 -0
- package/package.json +58 -0
- package/vendor/registry/blocks/blog-detail/module.json +27 -0
- package/vendor/registry/blocks/blog-detail/ui/minimal/next/blog-detail.tsx +26 -0
- package/vendor/registry/blocks/blog-detail/ui/minimal/nuxt/BlogDetail.vue +27 -0
- package/vendor/registry/blocks/blog-detail/ui/shadcn/next/blog-detail.tsx +106 -0
- package/vendor/registry/blocks/blog-detail/ui/shadcn/nuxt/BlogDetail.vue +116 -0
- package/vendor/registry/blocks/blog-list/module.json +26 -0
- package/vendor/registry/blocks/blog-list/ui/minimal/next/blog-list.tsx +130 -0
- package/vendor/registry/blocks/blog-list/ui/minimal/nuxt/BlogList.vue +62 -0
- package/vendor/registry/blocks/blog-list/ui/shadcn/next/blog-list.tsx +109 -0
- package/vendor/registry/blocks/blog-list/ui/shadcn/nuxt/BlogList.vue +100 -0
- package/vendor/registry/blocks/blog-list-cards/module.json +27 -0
- package/vendor/registry/blocks/blog-list-cards/ui/minimal/next/blog-list-cards.tsx +130 -0
- package/vendor/registry/blocks/blog-list-cards/ui/minimal/nuxt/BlogListCards.vue +114 -0
- package/vendor/registry/blocks/blog-list-cards/ui/shadcn/next/blog-list-cards.tsx +119 -0
- package/vendor/registry/blocks/blog-list-cards/ui/shadcn/nuxt/BlogListCards.vue +113 -0
- package/vendor/registry/blocks/booking-form-ui/module.json +15 -0
- package/vendor/registry/blocks/booking-form-ui/ui/minimal/next/booking-form.tsx +89 -0
- package/vendor/registry/blocks/booking-form-ui/ui/shadcn/next/booking-form.tsx +92 -0
- package/vendor/registry/blocks/contact-form-ui/module.json +27 -0
- package/vendor/registry/blocks/contact-form-ui/ui/minimal/next/contact-form.tsx +45 -0
- package/vendor/registry/blocks/contact-form-ui/ui/minimal/nuxt/ContactForm.vue +79 -0
- package/vendor/registry/blocks/contact-form-ui/ui/shadcn/next/contact-form.tsx +55 -0
- package/vendor/registry/blocks/contact-form-ui/ui/shadcn/nuxt/ContactForm.vue +92 -0
- package/vendor/registry/blocks/faq-list/module.json +15 -0
- package/vendor/registry/blocks/faq-list/ui/minimal/next/faq-list.tsx +78 -0
- package/vendor/registry/blocks/faq-list/ui/shadcn/next/faq-list.tsx +77 -0
- package/vendor/registry/blocks/maintenance-gate/module.json +13 -0
- package/vendor/registry/blocks/maintenance-gate/ui/minimal/next/maintenance-gate.tsx +135 -0
- package/vendor/registry/blocks/maintenance-gate/ui/shadcn/next/maintenance-gate.tsx +87 -0
- package/vendor/registry/blocks/nav-footer/module.json +13 -0
- package/vendor/registry/blocks/nav-footer/ui/minimal/next/nav-footer.tsx +55 -0
- package/vendor/registry/blocks/nav-footer/ui/shadcn/next/nav-footer.tsx +41 -0
- package/vendor/registry/blocks/nav-header/module.json +14 -0
- package/vendor/registry/blocks/nav-header/ui/minimal/next/nav-header.tsx +244 -0
- package/vendor/registry/blocks/nav-header/ui/shadcn/next/nav-header-client.tsx +185 -0
- package/vendor/registry/blocks/nav-header/ui/shadcn/next/nav-header.tsx +12 -0
- package/vendor/registry/blocks/page-detail/module.json +26 -0
- package/vendor/registry/blocks/page-detail/ui/minimal/next/page-detail.tsx +26 -0
- package/vendor/registry/blocks/page-detail/ui/minimal/nuxt/PageDetail.vue +26 -0
- package/vendor/registry/blocks/page-detail/ui/shadcn/next/page-detail.tsx +61 -0
- package/vendor/registry/blocks/page-detail/ui/shadcn/nuxt/PageDetail.vue +62 -0
- package/vendor/registry/blocks/project-detail/module.json +15 -0
- package/vendor/registry/blocks/project-detail/ui/minimal/next/project-detail.tsx +58 -0
- package/vendor/registry/blocks/project-detail/ui/shadcn/next/project-detail.tsx +91 -0
- package/vendor/registry/blocks/project-list/module.json +14 -0
- package/vendor/registry/blocks/project-list/ui/minimal/next/project-list.tsx +104 -0
- package/vendor/registry/blocks/project-list/ui/shadcn/next/project-list.tsx +81 -0
- package/vendor/registry/blocks/project-list-cards/module.json +15 -0
- package/vendor/registry/blocks/project-list-cards/ui/minimal/next/project-list-cards.tsx +125 -0
- package/vendor/registry/blocks/project-list-cards/ui/shadcn/next/project-list-cards.tsx +94 -0
- package/vendor/registry/blocks/projects-carousel/module.json +15 -0
- package/vendor/registry/blocks/projects-carousel/ui/minimal/next/projects-carousel-client.tsx +239 -0
- package/vendor/registry/blocks/projects-carousel/ui/minimal/next/projects-carousel.tsx +24 -0
- package/vendor/registry/blocks/projects-carousel/ui/shadcn/next/projects-carousel-client.tsx +102 -0
- package/vendor/registry/blocks/projects-carousel/ui/shadcn/next/projects-carousel.tsx +24 -0
- package/vendor/registry/blocks/service-detail/module.json +15 -0
- package/vendor/registry/blocks/service-detail/ui/minimal/next/service-detail.tsx +49 -0
- package/vendor/registry/blocks/service-detail/ui/shadcn/next/service-detail.tsx +75 -0
- package/vendor/registry/blocks/service-list/module.json +14 -0
- package/vendor/registry/blocks/service-list/ui/minimal/next/service-list.tsx +103 -0
- package/vendor/registry/blocks/service-list/ui/shadcn/next/service-list.tsx +80 -0
- package/vendor/registry/blocks/service-list-cards/module.json +15 -0
- package/vendor/registry/blocks/service-list-cards/ui/minimal/next/service-list-cards.tsx +124 -0
- package/vendor/registry/blocks/service-list-cards/ui/shadcn/next/service-list-cards.tsx +92 -0
- package/vendor/registry/blocks/site-brand/module.json +13 -0
- package/vendor/registry/blocks/site-brand/ui/minimal/next/site-brand.tsx +61 -0
- package/vendor/registry/blocks/site-brand/ui/shadcn/next/site-brand.tsx +48 -0
- package/vendor/registry/blocks/site-logo/module.json +13 -0
- package/vendor/registry/blocks/site-logo/ui/minimal/next/site-logo.tsx +37 -0
- package/vendor/registry/blocks/site-logo/ui/shadcn/next/site-logo.tsx +34 -0
- package/vendor/registry/blocks/social-links/module.json +13 -0
- package/vendor/registry/blocks/social-links/ui/minimal/next/social-links.tsx +55 -0
- package/vendor/registry/blocks/social-links/ui/shadcn/next/social-links.tsx +46 -0
- package/vendor/registry/blocks/team-detail/module.json +15 -0
- package/vendor/registry/blocks/team-detail/ui/minimal/next/team-detail.tsx +113 -0
- package/vendor/registry/blocks/team-detail/ui/shadcn/next/team-detail.tsx +77 -0
- package/vendor/registry/blocks/team-list/module.json +14 -0
- package/vendor/registry/blocks/team-list/ui/minimal/next/team-list.tsx +113 -0
- package/vendor/registry/blocks/team-list/ui/shadcn/next/team-list.tsx +77 -0
- package/vendor/registry/blocks/team-list-cards/module.json +15 -0
- package/vendor/registry/blocks/team-list-cards/ui/minimal/next/team-list-cards.tsx +111 -0
- package/vendor/registry/blocks/team-list-cards/ui/shadcn/next/team-list-cards.tsx +83 -0
- package/vendor/registry/blocks/testimonials-carousel/module.json +15 -0
- package/vendor/registry/blocks/testimonials-carousel/ui/minimal/next/testimonials-carousel-client.tsx +230 -0
- package/vendor/registry/blocks/testimonials-carousel/ui/minimal/next/testimonials-carousel.tsx +23 -0
- package/vendor/registry/blocks/testimonials-carousel/ui/shadcn/next/testimonials-carousel-client.tsx +91 -0
- package/vendor/registry/blocks/testimonials-carousel/ui/shadcn/next/testimonials-carousel.tsx +23 -0
- package/vendor/registry/blocks/testimonials-list/module.json +14 -0
- package/vendor/registry/blocks/testimonials-list/ui/minimal/next/testimonials-list.tsx +109 -0
- package/vendor/registry/blocks/testimonials-list/ui/shadcn/next/testimonials-list.tsx +72 -0
- package/vendor/registry/blocks/testimonials-list-cards/module.json +15 -0
- package/vendor/registry/blocks/testimonials-list-cards/ui/minimal/next/testimonials-list-cards.tsx +114 -0
- package/vendor/registry/blocks/testimonials-list-cards/ui/shadcn/next/testimonials-list-cards.tsx +72 -0
- package/vendor/registry/core/languages/policies.json +25 -0
- package/vendor/registry/core/languages/seed.json +16 -0
- package/vendor/registry/core/languages/snapshot.json +94 -0
- package/vendor/registry/modules/blog/access/policies.json +49 -0
- package/vendor/registry/modules/blog/access/policies.multilocale.json +67 -0
- package/vendor/registry/modules/blog/lib.multilocale.ts +552 -0
- package/vendor/registry/modules/blog/lib.ts +346 -0
- package/vendor/registry/modules/blog/module.json +50 -0
- package/vendor/registry/modules/blog/schema/snapshot.json +701 -0
- package/vendor/registry/modules/blog/schema/snapshot.multilocale.json +884 -0
- package/vendor/registry/modules/blog/services/ATTRIBUTION.md +8 -0
- package/vendor/registry/modules/blog/services/assets/ada-lovelace-avatar.jpg +0 -0
- package/vendor/registry/modules/blog/services/assets/hello-from-dkit-cover.jpg +0 -0
- package/vendor/registry/modules/blog/services/seed.json +70 -0
- package/vendor/registry/modules/blog/services/seed.multilocale.json +90 -0
- package/vendor/registry/modules/blog/types.multilocale.ts +96 -0
- package/vendor/registry/modules/blog/types.ts +62 -0
- package/vendor/registry/modules/booking-form/access/policies.json +25 -0
- package/vendor/registry/modules/booking-form/access/policies.multilocale.json +27 -0
- package/vendor/registry/modules/booking-form/lib.multilocale.ts +71 -0
- package/vendor/registry/modules/booking-form/lib.ts +77 -0
- package/vendor/registry/modules/booking-form/module.json +32 -0
- package/vendor/registry/modules/booking-form/schema/snapshot.json +294 -0
- package/vendor/registry/modules/booking-form/schema/snapshot.multilocale.json +467 -0
- package/vendor/registry/modules/booking-form/services/flows.json +19 -0
- package/vendor/registry/modules/booking-form/types.multilocale.ts +29 -0
- package/vendor/registry/modules/booking-form/types.ts +27 -0
- package/vendor/registry/modules/contact-form/access/policies.json +25 -0
- package/vendor/registry/modules/contact-form/access/policies.multilocale.json +27 -0
- package/vendor/registry/modules/contact-form/lib.multilocale.ts +65 -0
- package/vendor/registry/modules/contact-form/lib.ts +67 -0
- package/vendor/registry/modules/contact-form/module.json +32 -0
- package/vendor/registry/modules/contact-form/schema/snapshot.json +193 -0
- package/vendor/registry/modules/contact-form/schema/snapshot.multilocale.json +293 -0
- package/vendor/registry/modules/contact-form/services/flows.json +19 -0
- package/vendor/registry/modules/contact-form/types.multilocale.ts +21 -0
- package/vendor/registry/modules/contact-form/types.ts +19 -0
- package/vendor/registry/modules/faq/access/policies.json +25 -0
- package/vendor/registry/modules/faq/access/policies.multilocale.json +18 -0
- package/vendor/registry/modules/faq/lib.multilocale.ts +120 -0
- package/vendor/registry/modules/faq/lib.ts +73 -0
- package/vendor/registry/modules/faq/module.json +31 -0
- package/vendor/registry/modules/faq/schema/snapshot.json +180 -0
- package/vendor/registry/modules/faq/schema/snapshot.multilocale.json +116 -0
- package/vendor/registry/modules/faq/services/seed.json +38 -0
- package/vendor/registry/modules/faq/services/seed.multilocale.json +32 -0
- package/vendor/registry/modules/faq/types.multilocale.ts +31 -0
- package/vendor/registry/modules/faq/types.ts +17 -0
- package/vendor/registry/modules/navigation/access/policies.json +31 -0
- package/vendor/registry/modules/navigation/access/policies.multilocale.json +51 -0
- package/vendor/registry/modules/navigation/lib.multilocale.ts +198 -0
- package/vendor/registry/modules/navigation/lib.ts +252 -0
- package/vendor/registry/modules/navigation/module.json +46 -0
- package/vendor/registry/modules/navigation/schema/snapshot.json +453 -0
- package/vendor/registry/modules/navigation/schema/snapshot.multilocale.json +864 -0
- package/vendor/registry/modules/navigation/services/seed.json +103 -0
- package/vendor/registry/modules/navigation/services/seed.multilocale.json +88 -0
- package/vendor/registry/modules/navigation/types.multilocale.ts +60 -0
- package/vendor/registry/modules/navigation/types.ts +44 -0
- package/vendor/registry/modules/pages/access/policies.json +25 -0
- package/vendor/registry/modules/pages/access/policies.multilocale.json +18 -0
- package/vendor/registry/modules/pages/lib.multilocale.ts +166 -0
- package/vendor/registry/modules/pages/lib.ts +123 -0
- package/vendor/registry/modules/pages/module.json +39 -0
- package/vendor/registry/modules/pages/schema/snapshot.json +247 -0
- package/vendor/registry/modules/pages/schema/snapshot.multilocale.json +187 -0
- package/vendor/registry/modules/pages/services/seed.json +24 -0
- package/vendor/registry/modules/pages/services/seed.multilocale.json +34 -0
- package/vendor/registry/modules/pages/types.multilocale.ts +37 -0
- package/vendor/registry/modules/pages/types.ts +21 -0
- package/vendor/registry/modules/projects/access/policies.json +31 -0
- package/vendor/registry/modules/projects/access/policies.multilocale.json +43 -0
- package/vendor/registry/modules/projects/lib.multilocale.ts +111 -0
- package/vendor/registry/modules/projects/lib.ts +138 -0
- package/vendor/registry/modules/projects/module.json +48 -0
- package/vendor/registry/modules/projects/schema/snapshot.json +348 -0
- package/vendor/registry/modules/projects/schema/snapshot.multilocale.json +577 -0
- package/vendor/registry/modules/projects/services/ATTRIBUTION.md +7 -0
- package/vendor/registry/modules/projects/services/assets/brand-identity-cover.jpg +0 -0
- package/vendor/registry/modules/projects/services/seed.json +40 -0
- package/vendor/registry/modules/projects/services/seed.multilocale.json +31 -0
- package/vendor/registry/modules/projects/types.multilocale.ts +38 -0
- package/vendor/registry/modules/projects/types.ts +28 -0
- package/vendor/registry/modules/services/access/policies.json +31 -0
- package/vendor/registry/modules/services/access/policies.multilocale.json +43 -0
- package/vendor/registry/modules/services/lib.multilocale.ts +109 -0
- package/vendor/registry/modules/services/lib.ts +134 -0
- package/vendor/registry/modules/services/module.json +47 -0
- package/vendor/registry/modules/services/schema/snapshot.json +305 -0
- package/vendor/registry/modules/services/schema/snapshot.multilocale.json +510 -0
- package/vendor/registry/modules/services/services/ATTRIBUTION.md +8 -0
- package/vendor/registry/modules/services/services/assets/design-development.jpg +0 -0
- package/vendor/registry/modules/services/services/assets/strategy-consulting.jpg +0 -0
- package/vendor/registry/modules/services/services/seed.json +44 -0
- package/vendor/registry/modules/services/services/seed.multilocale.json +31 -0
- package/vendor/registry/modules/services/types.multilocale.ts +36 -0
- package/vendor/registry/modules/services/types.ts +26 -0
- package/vendor/registry/modules/settings/access/policies.json +31 -0
- package/vendor/registry/modules/settings/access/policies.multilocale.json +43 -0
- package/vendor/registry/modules/settings/lib.multilocale.ts +158 -0
- package/vendor/registry/modules/settings/lib.ts +259 -0
- package/vendor/registry/modules/settings/module.json +33 -0
- package/vendor/registry/modules/settings/schema/snapshot.json +315 -0
- package/vendor/registry/modules/settings/schema/snapshot.multilocale.json +586 -0
- package/vendor/registry/modules/settings/services/assets/dkit-logo.svg +4 -0
- package/vendor/registry/modules/settings/services/seed.json +31 -0
- package/vendor/registry/modules/settings/services/seed.multilocale.json +42 -0
- package/vendor/registry/modules/settings/types.multilocale.ts +72 -0
- package/vendor/registry/modules/settings/types.ts +94 -0
- package/vendor/registry/modules/team/access/policies.json +31 -0
- package/vendor/registry/modules/team/access/policies.multilocale.json +43 -0
- package/vendor/registry/modules/team/lib.multilocale.ts +88 -0
- package/vendor/registry/modules/team/lib.ts +120 -0
- package/vendor/registry/modules/team/module.json +47 -0
- package/vendor/registry/modules/team/schema/snapshot.json +295 -0
- package/vendor/registry/modules/team/schema/snapshot.multilocale.json +525 -0
- package/vendor/registry/modules/team/services/ATTRIBUTION.md +8 -0
- package/vendor/registry/modules/team/services/assets/morgan-lee-photo.jpg +0 -0
- package/vendor/registry/modules/team/services/assets/taylor-kim-photo.jpg +0 -0
- package/vendor/registry/modules/team/services/seed.json +52 -0
- package/vendor/registry/modules/team/services/seed.multilocale.json +30 -0
- package/vendor/registry/modules/team/types.multilocale.ts +33 -0
- package/vendor/registry/modules/team/types.ts +27 -0
- package/vendor/registry/modules/testimonials/access/policies.json +31 -0
- package/vendor/registry/modules/testimonials/access/policies.multilocale.json +43 -0
- package/vendor/registry/modules/testimonials/lib.multilocale.ts +93 -0
- package/vendor/registry/modules/testimonials/lib.ts +85 -0
- package/vendor/registry/modules/testimonials/module.json +41 -0
- package/vendor/registry/modules/testimonials/schema/snapshot.json +248 -0
- package/vendor/registry/modules/testimonials/schema/snapshot.multilocale.json +462 -0
- package/vendor/registry/modules/testimonials/services/ATTRIBUTION.md +8 -0
- package/vendor/registry/modules/testimonials/services/assets/jane-doe-avatar.jpg +0 -0
- package/vendor/registry/modules/testimonials/services/assets/sample-author-avatar.jpg +0 -0
- package/vendor/registry/modules/testimonials/services/seed.json +49 -0
- package/vendor/registry/modules/testimonials/services/seed.multilocale.json +30 -0
- package/vendor/registry/modules/testimonials/types.multilocale.ts +27 -0
- package/vendor/registry/modules/testimonials/types.ts +22 -0
- package/vendor/registry/registry.json +832 -0
- package/vendor/registry/shared/helpers.ts +16 -0
- package/vendor/registry/shared/i18n.ts +74 -0
- package/vendor/registry/shared/minimal.css +83 -0
- package/vendor/registry/shared/paths.ts +50 -0
- package/vendor/registry/shared/prose.css +113 -0
- package/vendor/registry/tsconfig.json +49 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"policies": [
|
|
3
|
+
{
|
|
4
|
+
"name": "dkit Navigation Public Read",
|
|
5
|
+
"icon": "public",
|
|
6
|
+
"description": "Public read for navigation incl. translation tables.",
|
|
7
|
+
"admin_access": false,
|
|
8
|
+
"app_access": false
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"permissions": [
|
|
12
|
+
{
|
|
13
|
+
"policy": "dkit Navigation Public Read",
|
|
14
|
+
"collection": "nav_menus",
|
|
15
|
+
"action": "read",
|
|
16
|
+
"fields": [
|
|
17
|
+
"*"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"policy": "dkit Navigation Public Read",
|
|
22
|
+
"collection": "nav_menus_translations",
|
|
23
|
+
"action": "read",
|
|
24
|
+
"fields": [
|
|
25
|
+
"*"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"policy": "dkit Navigation Public Read",
|
|
30
|
+
"collection": "nav_items",
|
|
31
|
+
"action": "read",
|
|
32
|
+
"fields": [
|
|
33
|
+
"*"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"policy": "dkit Navigation Public Read",
|
|
38
|
+
"collection": "nav_items_translations",
|
|
39
|
+
"action": "read",
|
|
40
|
+
"fields": [
|
|
41
|
+
"*"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"access": [
|
|
46
|
+
{
|
|
47
|
+
"role": "$public",
|
|
48
|
+
"policy": "dkit Navigation Public Read"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dkitQueryFailed,
|
|
3
|
+
getDirectus,
|
|
4
|
+
readItem,
|
|
5
|
+
readItems,
|
|
6
|
+
} from "@/lib/dkit/client";
|
|
7
|
+
import { collections } from "@/lib/dkit/config";
|
|
8
|
+
import { queryLimit, statusFilter } from "@/lib/dkit/helpers";
|
|
9
|
+
import {
|
|
10
|
+
pickTranslation,
|
|
11
|
+
requireLocaleTranslation,
|
|
12
|
+
resolveLocale,
|
|
13
|
+
translationsDeepFilter,
|
|
14
|
+
} from "@/lib/dkit/i18n";
|
|
15
|
+
import type {
|
|
16
|
+
GetNavItemsOptions,
|
|
17
|
+
GetNavMenuByKeyOptions,
|
|
18
|
+
GetNavMenusOptions,
|
|
19
|
+
NavItem,
|
|
20
|
+
NavItemTranslation,
|
|
21
|
+
NavMenu,
|
|
22
|
+
NavMenuTranslation,
|
|
23
|
+
NavMenuTree,
|
|
24
|
+
} from "./types.multilocale";
|
|
25
|
+
|
|
26
|
+
export type {
|
|
27
|
+
GetNavItemsOptions,
|
|
28
|
+
GetNavMenuByKeyOptions,
|
|
29
|
+
GetNavMenusOptions,
|
|
30
|
+
NavItem,
|
|
31
|
+
NavItemTranslation,
|
|
32
|
+
NavMenu,
|
|
33
|
+
NavMenuTranslation,
|
|
34
|
+
NavMenuTree,
|
|
35
|
+
} from "./types.multilocale";
|
|
36
|
+
|
|
37
|
+
function flattenMenu(row: Record<string, unknown>, locale: string): NavMenu {
|
|
38
|
+
const trans = pickTranslation(row.translations as NavMenuTranslation[] | undefined, locale);
|
|
39
|
+
return {
|
|
40
|
+
id: row.id as string,
|
|
41
|
+
status: row.status as NavMenu["status"],
|
|
42
|
+
name: trans?.name ?? "",
|
|
43
|
+
key: row.key as string,
|
|
44
|
+
description: trans?.description ?? null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function flattenItem(row: Record<string, unknown>, locale: string): NavItem | null {
|
|
49
|
+
const trans = pickTranslation(row.translations as NavItemTranslation[] | undefined, locale);
|
|
50
|
+
if (!trans?.label?.trim()) return null;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
id: row.id as string,
|
|
54
|
+
status: row.status as NavItem["status"],
|
|
55
|
+
menu: row.menu as NavItem["menu"],
|
|
56
|
+
parent: row.parent as NavItem["parent"],
|
|
57
|
+
label: trans.label,
|
|
58
|
+
href: trans?.href ?? "#",
|
|
59
|
+
open_in_new_tab: (row.open_in_new_tab as boolean | null) ?? null,
|
|
60
|
+
sort: (row.sort as number | null) ?? null,
|
|
61
|
+
children: row.children as NavItem[] | undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const MENU_FIELDS = [
|
|
66
|
+
"id", "status", "key",
|
|
67
|
+
{ translations: ["id", "languages_code", "name", "description"] },
|
|
68
|
+
] as const;
|
|
69
|
+
|
|
70
|
+
const ITEM_FIELDS = [
|
|
71
|
+
"id", "status", "open_in_new_tab", "sort", "parent",
|
|
72
|
+
{ menu: ["id", "key", "status"] },
|
|
73
|
+
{ translations: ["id", "languages_code", "label", "href"] },
|
|
74
|
+
] as const;
|
|
75
|
+
|
|
76
|
+
function parentId(item: NavItem): string | null {
|
|
77
|
+
if (!item.parent) return null;
|
|
78
|
+
if (typeof item.parent === "string") return item.parent;
|
|
79
|
+
return item.parent.id ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sortItems(a: NavItem, b: NavItem): number {
|
|
83
|
+
return (a.sort ?? 0) - (b.sort ?? 0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function buildNavTree(items: NavItem[]): NavItem[] {
|
|
87
|
+
const byId = new Map<string, NavItem>();
|
|
88
|
+
for (const item of items) byId.set(item.id, { ...item, children: [] });
|
|
89
|
+
const roots: NavItem[] = [];
|
|
90
|
+
for (const item of byId.values()) {
|
|
91
|
+
const pid = parentId(item);
|
|
92
|
+
if (pid && byId.has(pid)) byId.get(pid)!.children!.push(item);
|
|
93
|
+
else roots.push(item);
|
|
94
|
+
}
|
|
95
|
+
for (const node of byId.values()) node.children?.sort(sortItems);
|
|
96
|
+
return roots.sort(sortItems);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function isExternalHref(href: string): boolean {
|
|
100
|
+
return /^https?:\/\//i.test(href) || href.startsWith("//");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function navLinkProps(item: Pick<NavItem, "href" | "open_in_new_tab">): {
|
|
104
|
+
href: string; target?: "_blank"; rel?: string;
|
|
105
|
+
} {
|
|
106
|
+
const external = isExternalHref(item.href) || Boolean(item.open_in_new_tab);
|
|
107
|
+
return { href: item.href, ...(external ? { target: "_blank" as const, rel: "noopener noreferrer" } : {}) };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function fetchNavDescendants(
|
|
111
|
+
roots: NavItem[], status: Record<string, unknown> | undefined, locale: string,
|
|
112
|
+
): Promise<NavItem[]> {
|
|
113
|
+
const client = getDirectus();
|
|
114
|
+
if (!client || !collections.nav_items || roots.length === 0) return roots;
|
|
115
|
+
const all = [...roots];
|
|
116
|
+
let frontier = roots.map((i) => i.id);
|
|
117
|
+
while (frontier.length > 0) {
|
|
118
|
+
const childAnd: Record<string, unknown>[] = [
|
|
119
|
+
{ parent: { _in: frontier } },
|
|
120
|
+
requireLocaleTranslation(locale, ["label"]),
|
|
121
|
+
];
|
|
122
|
+
if (status) childAnd.unshift(status);
|
|
123
|
+
const kids = await client.request(readItems(collections.nav_items, {
|
|
124
|
+
filter: { _and: childAnd }, fields: [...ITEM_FIELDS], sort: ["sort"], limit: -1,
|
|
125
|
+
}));
|
|
126
|
+
if (!kids.length) break;
|
|
127
|
+
const flat = (kids as Record<string, unknown>[])
|
|
128
|
+
.map((r) => flattenItem(r, locale))
|
|
129
|
+
.filter((i): i is NavItem => i != null);
|
|
130
|
+
all.push(...flat);
|
|
131
|
+
frontier = flat.map((i) => i.id);
|
|
132
|
+
}
|
|
133
|
+
return all;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function getNavMenus(options: GetNavMenusOptions = {}): Promise<NavMenu[]> {
|
|
137
|
+
const client = getDirectus(); if (!client) return [];
|
|
138
|
+
if (!collections.nav_menus) { dkitQueryFailed('collections.nav_menus missing — re-run `dkit add navigation`'); return []; }
|
|
139
|
+
const locale = await resolveLocale(options.locale);
|
|
140
|
+
const limit = queryLimit(options.limit);
|
|
141
|
+
try {
|
|
142
|
+
const rows = await client.request(readItems(collections.nav_menus, {
|
|
143
|
+
filter: statusFilter(options.status),
|
|
144
|
+
deep: translationsDeepFilter(locale),
|
|
145
|
+
fields: [...MENU_FIELDS], sort: options.sort ?? ["name"],
|
|
146
|
+
...(limit !== undefined ? { limit } : {}),
|
|
147
|
+
}));
|
|
148
|
+
return (rows as Record<string, unknown>[]).map((r) => flattenMenu(r, locale));
|
|
149
|
+
} catch (err) { dkitQueryFailed(`getNavMenus failed`, err); return []; }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function getNavMenuById(id: string, options: { locale?: string } = {}): Promise<NavMenu | null> {
|
|
153
|
+
const client = getDirectus(); if (!client) return null; if (!collections.nav_menus) return null;
|
|
154
|
+
const locale = await resolveLocale(options.locale);
|
|
155
|
+
try {
|
|
156
|
+
const row = await client.request(readItem(collections.nav_menus, id, { fields: [...MENU_FIELDS] }));
|
|
157
|
+
return row ? flattenMenu(row as Record<string, unknown>, locale) : null;
|
|
158
|
+
} catch (err) { dkitQueryFailed(`getNavMenuById(${id}) failed`, err); return null; }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function getNavMenuByKey(key: string, options: GetNavMenuByKeyOptions = {}): Promise<NavMenuTree | null> {
|
|
162
|
+
const client = getDirectus(); if (!client) return null;
|
|
163
|
+
if (!collections.nav_menus || !collections.nav_items) { dkitQueryFailed("collections.nav_menus / nav_items missing"); return null; }
|
|
164
|
+
const locale = await resolveLocale(options.locale);
|
|
165
|
+
const status = statusFilter(options.status);
|
|
166
|
+
const menuAnd: Record<string, unknown>[] = [{ key: { _eq: key } }];
|
|
167
|
+
if (status) menuAnd.unshift(status);
|
|
168
|
+
try {
|
|
169
|
+
const menus = await client.request(readItems(collections.nav_menus, { filter: { _and: menuAnd }, fields: [...MENU_FIELDS], limit: 1 }));
|
|
170
|
+
const menu = (menus as Record<string, unknown>[])[0];
|
|
171
|
+
if (!menu) return null;
|
|
172
|
+
const fm = flattenMenu(menu, locale);
|
|
173
|
+
const rootAnd: Record<string, unknown>[] = [
|
|
174
|
+
{ menu: { _eq: fm.id } },
|
|
175
|
+
{ parent: { _null: true } },
|
|
176
|
+
requireLocaleTranslation(locale, ["label"]),
|
|
177
|
+
];
|
|
178
|
+
if (status) rootAnd.unshift(status);
|
|
179
|
+
const roots = await client.request(readItems(collections.nav_items, { filter: { _and: rootAnd }, fields: [...ITEM_FIELDS], sort: ["sort"], limit: -1 }));
|
|
180
|
+
const flatRoots = (roots as Record<string, unknown>[])
|
|
181
|
+
.map((r) => flattenItem(r, locale))
|
|
182
|
+
.filter((i): i is NavItem => i != null);
|
|
183
|
+
const items = await fetchNavDescendants(flatRoots, status, locale);
|
|
184
|
+
return { id: fm.id, key: fm.key, name: fm.name, items: buildNavTree(items) };
|
|
185
|
+
} catch (err) { dkitQueryFailed(`getNavMenuByKey(${key}) failed`, err); return null; }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export async function getNavItems(key: string, options: GetNavItemsOptions = {}): Promise<NavItem[]> {
|
|
189
|
+
const tree = await getNavMenuByKey(key, { status: options.status, locale: options.locale });
|
|
190
|
+
if (!tree) return [];
|
|
191
|
+
if (options.tree === false) {
|
|
192
|
+
const flat: NavItem[] = [];
|
|
193
|
+
const walk = (nodes: NavItem[]) => { for (const n of nodes) { flat.push(n); if (n.children?.length) walk(n.children); } };
|
|
194
|
+
walk(tree.items);
|
|
195
|
+
return flat;
|
|
196
|
+
}
|
|
197
|
+
return tree.items;
|
|
198
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dkitQueryFailed,
|
|
3
|
+
getDirectus,
|
|
4
|
+
readItem,
|
|
5
|
+
readItems,
|
|
6
|
+
} from "@/lib/dkit/client";
|
|
7
|
+
import { collections } from "@/lib/dkit/config";
|
|
8
|
+
import { queryLimit, statusFilter } from "@/lib/dkit/helpers";
|
|
9
|
+
import type {
|
|
10
|
+
GetNavItemsOptions,
|
|
11
|
+
GetNavMenuByKeyOptions,
|
|
12
|
+
GetNavMenusOptions,
|
|
13
|
+
NavItem,
|
|
14
|
+
NavMenu,
|
|
15
|
+
NavMenuTree,
|
|
16
|
+
} from "./types";
|
|
17
|
+
|
|
18
|
+
export type {
|
|
19
|
+
GetNavItemsOptions,
|
|
20
|
+
GetNavMenuByKeyOptions,
|
|
21
|
+
GetNavMenusOptions,
|
|
22
|
+
NavItem,
|
|
23
|
+
NavMenu,
|
|
24
|
+
NavMenuTree,
|
|
25
|
+
} from "./types";
|
|
26
|
+
|
|
27
|
+
const MENU_FIELDS = [
|
|
28
|
+
"id",
|
|
29
|
+
"status",
|
|
30
|
+
"name",
|
|
31
|
+
"key",
|
|
32
|
+
"description",
|
|
33
|
+
] as const;
|
|
34
|
+
|
|
35
|
+
const ITEM_FIELDS = [
|
|
36
|
+
"id",
|
|
37
|
+
"status",
|
|
38
|
+
"label",
|
|
39
|
+
"href",
|
|
40
|
+
"open_in_new_tab",
|
|
41
|
+
"sort",
|
|
42
|
+
"parent",
|
|
43
|
+
{ menu: ["id", "key", "name", "status"] },
|
|
44
|
+
] as const;
|
|
45
|
+
|
|
46
|
+
function parentId(item: NavItem): string | null {
|
|
47
|
+
if (!item.parent) return null;
|
|
48
|
+
if (typeof item.parent === "string") return item.parent;
|
|
49
|
+
return item.parent.id ?? null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function sortItems(a: NavItem, b: NavItem): number {
|
|
53
|
+
return (a.sort ?? 0) - (b.sort ?? 0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Walk parent → children until the branch is exhausted. */
|
|
57
|
+
async function fetchNavDescendants(
|
|
58
|
+
roots: NavItem[],
|
|
59
|
+
status: Record<string, unknown> | undefined,
|
|
60
|
+
): Promise<NavItem[]> {
|
|
61
|
+
const client = getDirectus();
|
|
62
|
+
if (!client || !collections.nav_items || roots.length === 0) return roots;
|
|
63
|
+
|
|
64
|
+
const all = [...roots];
|
|
65
|
+
let frontier = roots.map((item) => item.id);
|
|
66
|
+
|
|
67
|
+
while (frontier.length > 0) {
|
|
68
|
+
const childAnd: Record<string, unknown>[] = [
|
|
69
|
+
{ parent: { _in: frontier } },
|
|
70
|
+
];
|
|
71
|
+
if (status) childAnd.unshift(status);
|
|
72
|
+
|
|
73
|
+
const kids = (await client.request(
|
|
74
|
+
readItems(collections.nav_items, {
|
|
75
|
+
filter: { _and: childAnd },
|
|
76
|
+
fields: [...ITEM_FIELDS],
|
|
77
|
+
sort: ["sort"],
|
|
78
|
+
limit: -1,
|
|
79
|
+
}),
|
|
80
|
+
)) as NavItem[];
|
|
81
|
+
if (!kids.length) break;
|
|
82
|
+
all.push(...kids);
|
|
83
|
+
frontier = kids.map((item) => item.id);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return all;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Build a tree from a flat item list (roots + nested Sub-items). */
|
|
90
|
+
export function buildNavTree(items: NavItem[]): NavItem[] {
|
|
91
|
+
const byId = new Map<string, NavItem>();
|
|
92
|
+
for (const item of items) {
|
|
93
|
+
byId.set(item.id, { ...item, children: [] });
|
|
94
|
+
}
|
|
95
|
+
const roots: NavItem[] = [];
|
|
96
|
+
for (const item of byId.values()) {
|
|
97
|
+
const pid = parentId(item);
|
|
98
|
+
if (pid && byId.has(pid)) {
|
|
99
|
+
byId.get(pid)!.children!.push(item);
|
|
100
|
+
} else {
|
|
101
|
+
roots.push(item);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const node of byId.values()) {
|
|
105
|
+
node.children?.sort(sortItems);
|
|
106
|
+
}
|
|
107
|
+
return roots.sort(sortItems);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function isExternalHref(href: string): boolean {
|
|
111
|
+
return /^https?:\/\//i.test(href) || href.startsWith("//");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function navLinkProps(item: Pick<NavItem, "href" | "open_in_new_tab">): {
|
|
115
|
+
href: string;
|
|
116
|
+
target?: "_blank";
|
|
117
|
+
rel?: string;
|
|
118
|
+
} {
|
|
119
|
+
const external = isExternalHref(item.href) || Boolean(item.open_in_new_tab);
|
|
120
|
+
return {
|
|
121
|
+
href: item.href,
|
|
122
|
+
...(external ? { target: "_blank" as const, rel: "noopener noreferrer" } : {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function getNavMenus(
|
|
127
|
+
options: GetNavMenusOptions = {},
|
|
128
|
+
): Promise<NavMenu[]> {
|
|
129
|
+
const client = getDirectus();
|
|
130
|
+
if (!client) return [];
|
|
131
|
+
if (!collections.nav_menus) {
|
|
132
|
+
dkitQueryFailed(
|
|
133
|
+
'collections.nav_menus missing from lib/dkit/config — re-run `dkit add navigation`',
|
|
134
|
+
);
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const limit = queryLimit(options.limit);
|
|
138
|
+
try {
|
|
139
|
+
return await client.request(
|
|
140
|
+
readItems(collections.nav_menus, {
|
|
141
|
+
filter: statusFilter(options.status),
|
|
142
|
+
fields: [...MENU_FIELDS],
|
|
143
|
+
sort: options.sort ?? ["name"],
|
|
144
|
+
...(limit !== undefined ? { limit } : {}),
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
dkitQueryFailed(
|
|
149
|
+
`getNavMenus failed (collection=${collections.nav_menus})`,
|
|
150
|
+
err,
|
|
151
|
+
);
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function getNavMenuById(id: string): Promise<NavMenu | null> {
|
|
157
|
+
const client = getDirectus();
|
|
158
|
+
if (!client) return null;
|
|
159
|
+
if (!collections.nav_menus) return null;
|
|
160
|
+
try {
|
|
161
|
+
return await client.request(
|
|
162
|
+
readItem(collections.nav_menus, id, {
|
|
163
|
+
fields: [...MENU_FIELDS],
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
} catch (err) {
|
|
167
|
+
dkitQueryFailed(`getNavMenuById(${id}) failed`, err);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Load a menu by key (`primary`, `footer`, …) with nested items.
|
|
174
|
+
* Soft-fails to null when missing or Directus is down.
|
|
175
|
+
*/
|
|
176
|
+
export async function getNavMenuByKey(
|
|
177
|
+
key: string,
|
|
178
|
+
options: GetNavMenuByKeyOptions = {},
|
|
179
|
+
): Promise<NavMenuTree | null> {
|
|
180
|
+
const client = getDirectus();
|
|
181
|
+
if (!client) return null;
|
|
182
|
+
if (!collections.nav_menus || !collections.nav_items) {
|
|
183
|
+
dkitQueryFailed("collections.nav_menus / nav_items missing from config");
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const status = statusFilter(options.status);
|
|
187
|
+
const menuAnd: Record<string, unknown>[] = [{ key: { _eq: key } }];
|
|
188
|
+
if (status) menuAnd.unshift(status);
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const menus = await client.request(
|
|
192
|
+
readItems(collections.nav_menus, {
|
|
193
|
+
filter: { _and: menuAnd },
|
|
194
|
+
fields: [...MENU_FIELDS],
|
|
195
|
+
limit: 1,
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
const menu = menus[0];
|
|
199
|
+
if (!menu) return null;
|
|
200
|
+
|
|
201
|
+
// Top-level rows own the menu FK; nested Sub-items only set `parent`.
|
|
202
|
+
const rootAnd: Record<string, unknown>[] = [
|
|
203
|
+
{ menu: { _eq: menu.id } },
|
|
204
|
+
{ parent: { _null: true } },
|
|
205
|
+
];
|
|
206
|
+
if (status) rootAnd.unshift(status);
|
|
207
|
+
|
|
208
|
+
const roots = await client.request(
|
|
209
|
+
readItems(collections.nav_items, {
|
|
210
|
+
filter: { _and: rootAnd },
|
|
211
|
+
fields: [...ITEM_FIELDS],
|
|
212
|
+
sort: ["sort"],
|
|
213
|
+
limit: -1,
|
|
214
|
+
}),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const items = await fetchNavDescendants(roots, status);
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
id: menu.id,
|
|
221
|
+
key: menu.key,
|
|
222
|
+
name: menu.name,
|
|
223
|
+
items: buildNavTree(items),
|
|
224
|
+
};
|
|
225
|
+
} catch (err) {
|
|
226
|
+
dkitQueryFailed(`getNavMenuByKey(${key}) failed`, err);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Items for a menu key. Default returns a nested tree; pass `{ tree: false }` for flat.
|
|
233
|
+
*/
|
|
234
|
+
export async function getNavItems(
|
|
235
|
+
key: string,
|
|
236
|
+
options: GetNavItemsOptions = {},
|
|
237
|
+
): Promise<NavItem[]> {
|
|
238
|
+
const tree = await getNavMenuByKey(key, { status: options.status });
|
|
239
|
+
if (!tree) return [];
|
|
240
|
+
if (options.tree === false) {
|
|
241
|
+
const flat: NavItem[] = [];
|
|
242
|
+
const walk = (nodes: NavItem[]) => {
|
|
243
|
+
for (const n of nodes) {
|
|
244
|
+
flat.push(n);
|
|
245
|
+
if (n.children?.length) walk(n.children);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
walk(tree.items);
|
|
249
|
+
return flat;
|
|
250
|
+
}
|
|
251
|
+
return tree.items;
|
|
252
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "dkit:module",
|
|
3
|
+
"id": "navigation",
|
|
4
|
+
"title": "Navigation",
|
|
5
|
+
"description": "Named menus and link trees for headers, footers, and inline nav",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"directus": {
|
|
8
|
+
"min": "11.0.0"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": [
|
|
11
|
+
"@directus/sdk"
|
|
12
|
+
],
|
|
13
|
+
"layers": [
|
|
14
|
+
"schema",
|
|
15
|
+
"access",
|
|
16
|
+
"services",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
19
|
+
"defaultBlocks": [
|
|
20
|
+
"nav-header",
|
|
21
|
+
"nav-footer"
|
|
22
|
+
],
|
|
23
|
+
"templates": {
|
|
24
|
+
"header": {
|
|
25
|
+
"default": "nav-header",
|
|
26
|
+
"options": [
|
|
27
|
+
"nav-header"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"footer": {
|
|
31
|
+
"default": "nav-footer",
|
|
32
|
+
"options": [
|
|
33
|
+
"nav-footer"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"collections": [
|
|
38
|
+
"site",
|
|
39
|
+
"nav_menus",
|
|
40
|
+
"nav_items"
|
|
41
|
+
],
|
|
42
|
+
"multilocale": {
|
|
43
|
+
"supported": true,
|
|
44
|
+
"mode": "translations"
|
|
45
|
+
}
|
|
46
|
+
}
|