Skip to content

Commit f5cc85e

Browse files
committed
feat: add api
1 parent 125f242 commit f5cc85e

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

demo/utils/ChangeLogButton.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ export default defineComponent({
1717
},
1818
props: {
1919
text: Boolean,
20-
id: String,
2120
quaternary: Boolean,
2221
size: {
2322
type: String as PropType<ButtonProps['size']>,
2423
default: 'small'
2524
}
2625
},
27-
setup(props) {
26+
setup() {
2827
const route = useRoute()
2928
const themeVars = useThemeVars()
29+
const miscMap: { [key: string]: string } = {
30+
discrete: 'createDiscreteApi'
31+
}
3032
const isCN = route.path.startsWith('/zh-CN')
31-
const componentName = `n-${props.id?.split('-').slice(1).join('-').toLowerCase()}`
33+
const name = route.fullPath.split('/').pop()
34+
const componentName = miscMap[name as string] || `n-${name}`
3235
const logs = isCN ? zhCN[componentName] : enUS[componentName]
3336
const drawerRef = ref(false)
3437
const renderer = new marked.Renderer()

demo/utils/EditOnGithubHeader.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export default defineComponent({
2323
}
2424
},
2525
setup() {
26-
const components = zhComponentRoutes.map((route: any) => route.path)
2726
const route = useRoute()
27+
const components = zhComponentRoutes.map((route: any) => route.path)
2828
const isComponent = components.includes(route.fullPath.split('/').pop())
2929
return {
3030
...i18n({
@@ -67,7 +67,7 @@ export default defineComponent({
6767
<span v-if="isComponent" class="edit-button">
6868
<n-tooltip placement="right" :show-arrow="false">
6969
<template #trigger>
70-
<ChangeLogButton :id="id" text quaternary />
70+
<ChangeLogButton quaternary />
7171
</template>
7272
{{ t('changeLog') }}
7373
</n-tooltip>

scripts/gen-component-changelog.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,29 @@ function parseChangelog(content) {
3333
}
3434

3535
const componentMatch = line.match(/^- .*?`(n-[^`]*)`/)
36-
if (!componentMatch)
37-
return
36+
const apiMatch = line.match(/^- .*?`([^`]*Api)`/)
37+
38+
const name = componentMatch
39+
? componentMatch[1]
40+
: apiMatch
41+
? apiMatch[1]
42+
: ''
3843

39-
const componentName = componentMatch[1]
4044
const content = isBreaking ? `${line.trim()} 🚨` : `${line.trim()}`
4145

42-
if (!logs[componentName]) {
43-
logs[componentName] = []
46+
if (!logs[name]) {
47+
logs[name] = []
4448
}
4549

46-
const existingLog = logs[componentName].find(
50+
const existingLog = logs[name].find(
4751
log => log.version === version && log.date === date
4852
)
4953

5054
if (existingLog) {
5155
existingLog.changes.push(content)
5256
}
5357
else {
54-
logs[componentName].push({
58+
logs[name].push({
5559
version,
5660
date,
5761
changes: [content]

src/discrete/demos/enUS/index.demo-entry.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Discrete API(v2.29.0)
1+
# Discrete API
22

33
If you want to use `useDialog`, `useMessage`, `useNotification`, `useLoadingBar`, `useModal` outside `setup`, you can use `createDiscreteApi` to create corresponding API.
44

55
<n-alert title="Caveat" type="warning" :bordered="false">
66
1. Discrete API won't be affected by <n-text code>n-xxx-provider</n-text> in current app. If you need to share config, you should sync them manually. Also, you'd better not using discrete API and normal API together. 2. Do not call <n-text code>createDiscreteApi</n-text> in <n-text code>setup</n-text> since it may cause some unexpected behaviors.
77
</n-alert>
88

9+
Available since `2.29.1`.
10+
911
## Demo
1012

1113
```demo

src/discrete/demos/zhCN/index.demo-entry.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# 脱离上下文的 API(v2.29.0)
1+
# 脱离上下文的 API CreateDiscreteAPI
22

33
如果你想在 `setup` 外使用 `useDialog``useMessage``useNotification``useLoadingBar``useModal`,可以通过 `createDiscreteApi` 来构建对应的 API。
44

55
<n-alert title="注意" type="warning" :bordered="false">
66
1. 脱离上下文的 API 不会受 <n-text code>n-xxx-provider</n-text> 的影响,并且和应用上下文中对应组件会使用不同的 DOM 容器。如果需要的话,你需要手动同步这些信息。并且最好不要混用两类 API。2. 不要在 <n-text code>setup</n-text> 中调用 <n-text code>createDiscreteApi</n-text>,可能会有一些意外的问题出现。
77
</n-alert>
88

9+
`2.29.1` 开始提供。
10+
911
## 演示
1012

1113
```demo

0 commit comments

Comments
 (0)