-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: split global and roadiz type utils * docs: fix comment * feat(VRoadizLink): more generic types * feat(roadiz): add plaholder types * feat: add VMainMenu * feat: add VMainMenu * chore: comment empty style block
- Loading branch information
1 parent
74913a0
commit 960d1a0
Showing
11 changed files
with
299 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<script setup lang="ts"> | ||
import { http, HttpResponse } from 'msw' | ||
import type { CommonContent } from '~/types/api' | ||
const menuIsOpen = ref(true) | ||
useMockRequest(http.get('*/common_content', () => { | ||
return HttpResponse.json({ | ||
menus: { | ||
mainMenuWalker: { | ||
'@id': '1', | ||
'@type': 'menu', | ||
'item': { | ||
'@id': 'menu 1', | ||
'@type': 'menu', | ||
'title': 'Main menu', | ||
}, | ||
'children': [ | ||
{ | ||
'@id': 'child-1', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Item 1', | ||
'linkExternalUrl': 'https://example.com', | ||
}, | ||
'children': [], | ||
}, | ||
{ | ||
'@id': 'child-2', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Item 2', | ||
'linkInternalReference': [ | ||
{ | ||
'@id': '1', | ||
'@type': 'NSPage', | ||
'title': 'Page 1', | ||
'url': '/page-1', | ||
}, | ||
], | ||
}, | ||
'children': [], | ||
}, | ||
{ | ||
'@id': 'child-3', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSNeutral', | ||
'title': 'Item 3', | ||
}, | ||
'children': [ | ||
{ | ||
'@id': 'sub-child-1', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Sub item 1', | ||
'linkExternalUrl': 'https://example.com', | ||
}, | ||
'children': [], | ||
}, | ||
{ | ||
'@id': 'sub-child-2', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Sub item 2', | ||
'linkInternalReference': [ | ||
{ | ||
'@id': '1', | ||
'@type': 'NSPage', | ||
'title': 'Page 2', | ||
'url': '/page-2', | ||
}, | ||
], | ||
}, | ||
'children': [], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
} satisfies CommonContent) | ||
})) | ||
</script> | ||
|
||
<template> | ||
<NuxtStory layout="fullscreen"> | ||
<ClientOnly> | ||
<VMainMenu v-model:open="menuIsOpen" /> | ||
</ClientOnly> | ||
</NuxtStory> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<script lang="ts" setup> | ||
import { http, HttpResponse } from 'msw' | ||
import type { CommonContent } from '~/types/api' | ||
const menuIsOpen = ref(false) | ||
useMockRequest(http.get('*/common_content', () => { | ||
return HttpResponse.json({ | ||
menus: { | ||
mainMenuWalker: { | ||
'@id': '1', | ||
'@type': 'menu', | ||
'item': { | ||
'@id': 'menu 1', | ||
'@type': 'menu', | ||
'title': 'Main menu', | ||
}, | ||
'children': [ | ||
{ | ||
'@id': 'child-1', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Item 1', | ||
'linkExternalUrl': 'https://example.com', | ||
}, | ||
'children': [], | ||
}, | ||
{ | ||
'@id': 'child-2', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Item 2', | ||
'linkInternalReference': [ | ||
{ | ||
'@id': '1', | ||
'@type': 'NSPage', | ||
'title': 'Page 1', | ||
'url': '/page-1', | ||
}, | ||
], | ||
}, | ||
'children': [], | ||
}, | ||
{ | ||
'@id': 'child-3', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSNeutral', | ||
'title': 'Item 3', | ||
}, | ||
'children': [ | ||
{ | ||
'@id': 'sub-child-1', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Sub item 1', | ||
'linkExternalUrl': 'https://example.com', | ||
}, | ||
'children': [], | ||
}, | ||
{ | ||
'@id': 'sub-child-2', | ||
'@type': 'NSMenuLink', | ||
'item': { | ||
'@id': '1', | ||
'@type': 'NSMenuLink', | ||
'title': 'Sub item 2', | ||
'linkInternalReference': [ | ||
{ | ||
'@id': '1', | ||
'@type': 'NSPage', | ||
'title': 'Page 2', | ||
'url': '/page-2', | ||
}, | ||
], | ||
}, | ||
'children': [], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
} satisfies CommonContent) | ||
})) | ||
</script> | ||
|
||
<template> | ||
<NuxtStory layout="fullscreen"> | ||
<VButton | ||
filled | ||
@click="menuIsOpen = !menuIsOpen" | ||
> | ||
Open | ||
</VButton> | ||
<VMainMenu v-model:open="menuIsOpen" /> | ||
</NuxtStory> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script lang="ts" setup> | ||
import type { NSMenuLink } from '~/types/roadiz' | ||
const isOpen = defineModel<boolean>('open') | ||
const { mainMenuWalker } = await useCommonContent() | ||
const route = useRoute() | ||
watch( | ||
() => route.fullPath, | ||
() => { | ||
isOpen.value = false | ||
}, | ||
) | ||
</script> | ||
|
||
<template> | ||
<VModal | ||
v-model="isOpen" | ||
align="right" | ||
> | ||
<nav> | ||
<ul v-if="mainMenuWalker?.children"> | ||
<li | ||
v-for="child in mainMenuWalker.children" | ||
:key="child.item?.['@id']" | ||
> | ||
<VRoadizLink | ||
v-if="(child.item as NSMenuLink)?.linkExternalUrl || (child.item as NSMenuLink)?.linkInternalReference" | ||
:url="(child.item as NSMenuLink)?.linkExternalUrl" | ||
:reference="(child.item as NSMenuLink)?.linkInternalReference" | ||
> | ||
{{ child.item?.title }} | ||
</VRoadizLink> | ||
<span v-else>{{ child.item?.title }}</span> | ||
<ul v-if="child.children"> | ||
<li | ||
v-for="subChild in child.children" | ||
:key="subChild.item?.['@id']" | ||
> | ||
<VRoadizLink | ||
:url="(subChild.item as NSMenuLink)?.linkExternalUrl" | ||
:reference="(subChild.item as NSMenuLink)?.linkInternalReference" | ||
> | ||
{{ subChild.item?.title }} | ||
</VRoadizLink> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</nav> | ||
</VModal> | ||
</template> | ||
|
||
<!-- <style lang="scss" module> --> | ||
<!-- </style> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
/* | ||
* This is an automated Roadiz interface declaration file. | ||
* This file content should be replaced entirely with new types definitions exported from Roadiz. | ||
* | ||
* RoadizNodesSources, RoadizDocument and other mentioned types are part of | ||
* roadiz/abstract-api-client package which must be installed in your project. | ||
* @roadiz/types package which must be installed in your project. | ||
* | ||
* @see https://github.com/roadiz/abstract-api-client | ||
* @see https://github.com/roadiz/types#readme | ||
* | ||
* Roadiz CMS node-types interfaces | ||
* | ||
* @see https://docs.roadiz.io/en/latest/developer/nodes-system/intro.html#what-is-a-node-type | ||
*/ | ||
|
||
import type { RoadizNodesSources } from '@roadiz/types' | ||
|
||
export type NSMenu = RoadizNodesSources | ||
|
||
export interface NSMenuLink extends RoadizNodesSources { | ||
linkExternalUrl?: string | ||
linkInternalReference?: Array<RoadizNodesSources> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { JsonLdObject, RoadizNodesSources } from '@roadiz/types' | ||
|
||
export interface RoadizWalkerKnown<Item = RoadizNodesSources, Child = RoadizNodesSources> extends JsonLdObject { | ||
item: Item | ||
children: RoadizWalkerKnown<Child>[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
// ROADIZ | ||
import type { RoadizNodesSources, JsonLdObject } from '@roadiz/types' | ||
|
||
export interface RoadizWalkerKnown<T = RoadizNodesSources, C = RoadizNodesSources> extends JsonLdObject { | ||
item: T | ||
children: RoadizWalkerKnown<C>[] | ||
} | ||
|
||
// COMMONS | ||
export type Writeable<T> = { -readonly [P in keyof T]: T[P] } | ||
|
||
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never | ||
|
||
export type ValueOf<T> = T extends unknown[] ? T[number] : T[keyof T] |