-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve api parser and json schema for vue (#2051)
* feat: add functional component/generic component support * feat: add more typedoc/jsdoc tags version control and release related tags * fix: expose outside props * feat: add externalSymbolLinkMap support * fix: readme * fix: tests run on windows * feat: add source reference for interface, type alias, type params * fix: vue demo * fix: dynamic git revision * fix: tests on windows * refactor: remove version * feat: use dumi built-in function to generate source links
- Loading branch information
Showing
61 changed files
with
4,071 additions
and
1,167 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
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
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
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
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,70 @@ | ||
import { | ||
SetupContext, | ||
defineComponent, | ||
onMounted, | ||
ref, | ||
shallowRef, | ||
type SlotsType, | ||
} from 'vue'; | ||
|
||
export type BaseItem = { id: string | number; text: string }; | ||
|
||
export interface ListProps<Item extends BaseItem> { | ||
/** | ||
* data source | ||
*/ | ||
source: () => Promise<Array<Item>> | Array<Item>; | ||
/** | ||
* trigger when data have been loaded | ||
* @deprecated | ||
*/ | ||
onLoaded?: (data: Array<Item>) => void; | ||
} | ||
|
||
export interface ListSlotsType<Item extends BaseItem> { | ||
item?: { item: Item }; | ||
} | ||
|
||
/** | ||
* @component | ||
* Generic components must use `@component`, because defineComponent returns just a plain function | ||
*/ | ||
export const List = defineComponent(function <Item extends BaseItem = BaseItem>( | ||
{ source, onLoaded }: ListProps<Item>, | ||
{ slots, expose }: SetupContext<{}, SlotsType<ListSlotsType<Item>>>, | ||
) { | ||
const list = shallowRef<Array<Item>>([]); | ||
const loading = ref(false); | ||
|
||
async function load() { | ||
loading.value = true; | ||
const data = await source(); | ||
list.value = data; | ||
loading.value = false; | ||
onLoaded?.(data); | ||
} | ||
|
||
expose({ | ||
// 遗憾的是这种函数定义方式,解析器并不能抽取imperative数据 | ||
load, | ||
}); | ||
|
||
onMounted(async () => { | ||
load(); | ||
}); | ||
return () => ( | ||
<> | ||
{loading.value ? ( | ||
'loading...' | ||
) : ( | ||
<ul> | ||
{list.value.map((item) => ( | ||
<li key={item.id}> | ||
{slots.item ? slots.item({ item }) : item.text} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</> | ||
); | ||
}); |
Oops, something went wrong.