Skip to content

Commit

Permalink
feat: add types (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
gd4Ark authored Nov 11, 2020
1 parent e7f9c62 commit 4588ed5
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 13 deletions.
13 changes: 13 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 在 TypeScript 中指定组件的类型

```html
<script lang="ts">
// 需要引入这个
// import { VGanttType } from '@femessage/v-gantt'
export default {
mounted() {
;(this.$refs.vGantt as VGanttType).collapsedMap[0] = true
},
}
</script>
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"browser": {
"./sfc": "src/index.vue"
},
"types": "src/index.d.ts",
"scripts": {
"dev": "vue-cli-service styleguidist",
"build": "yarn build:umd & yarn build:esm & yarn doc",
Expand Down
124 changes: 124 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {
GanttPropData,
GanttData,
GanttItem,
CollapsedMap,
GanttPropNode,
Bus,
GanttNode,
ColUnit,
} from './utils/types'
import Vue, { VueConstructor, PropType } from 'vue'

declare module '@femessage/v-gantt' {
class FemessageComponent extends Vue {
static install(vue: typeof Vue): void
}

type CombinedVueInstance<
Instance extends Vue,
Data,
Methods,
Computed,
Props
> = Data & Methods & Computed & Props & Instance

type ExtendedVue<
Instance extends Vue,
Data,
Methods,
Computed,
Props
> = VueConstructor<
CombinedVueInstance<Instance, Data, Methods, Computed, Props> & Vue
>

type Combined<Data, Methods, Computed, Props> = Data &
Methods &
Computed &
Props

type VGanttData = {
collapsedMap: CollapsedMap

scrollTop: number

dragData: {
node: null | GanttNode
movedCols: number
}

resizeData: {
node: null | GanttNode
resizedCols: number
}

bus: Bus
}

type VGanttMethods = {
initBus: () => void

onDelete: ({
id,
done,
}: {
id: GanttPropNode['id']
done: Function
}) => void

onMove: ({
id,
pid,
index,
done,
}: {
id: GanttPropNode['id']
pid?: GanttPropNode['id']
index: number
done: Function
}) => void

onDragStart: ({ id }: { id: GanttItem['id'] }) => void

onDrag: ({ movedCols }: { movedCols: number }) => void

onDragEnd: () => void

onResizeStart: ({ id }: { id: GanttItem['id'] }) => void

onResize: ({ resizedCols }: { resizedCols: number }) => void

onResizeEnd: () => void
}

type VGanttComputed = {
ganttData: GanttData
}

type VGanttProps = {
rowH: number

colW: number

data: PropType<GanttPropData>

view: PropType<ColUnit>

treeAttrs: { [key: string]: any }
}

type VGantt = Combined<VGanttData, VGanttMethods, VGanttComputed, VGanttProps>

export interface VGanttType extends FemessageComponent, VGantt {}

const VGanttConstruction: ExtendedVue<
Vue,
VGanttData,
VGanttMethods,
VGanttComputed,
VGanttProps
>

export default VGanttConstruction
}
47 changes: 34 additions & 13 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@
const path = require('path')
const glob = require('glob')

const sections = (() => {
const docs = glob
.sync('docs/*.md')
.map((p) => ({ name: path.basename(p, '.md'), content: p }))
const demos = []
let faq = '' // 约定至多只有一个faq.md
const guides = []
docs.forEach((d) => {
if (/^faq$/i.test(d.name)) {
d.name = d.name.toUpperCase()
faq = d
} else if (/^guide-/.test(d.name)) {
guides.push(d)
} else {
demos.push(d)
}
})
return [
{
name: 'Components',
components: 'src/index.vue',
usageMode: 'expand',
},
{
name: 'Demo',
sections: demos,
sectionDepth: 2,
},
...(faq ? [faq] : []),
...(guides.length ? [{ name: 'Guide', sections: guides }] : []),
]
})()

module.exports = {
title: 'v-gantt 文档',
styleguideDir: 'docs',
Expand All @@ -11,19 +44,7 @@ module.exports = {
url: 'https://github.com/FEMessage/v-gantt',
},
require: ['./styleguide.config.extra.js'],
sections: [
{
name: 'Components',
components: 'src/index.vue',
usageMode: 'expand',
},
{
name: 'Demo',
sections: glob
.sync('docs/*.md')
.map((p) => ({ name: path.basename(p, '.md'), content: p })),
},
],
sections,
exampleMode: 'expand',
dangerouslyUpdateWebpackConfig(webpackConfig) {
/**
Expand Down

0 comments on commit 4588ed5

Please sign in to comment.