Skip to content

Commit 9a3fd31

Browse files
authored
Fix typings (#443)
1 parent 2a34160 commit 9a3fd31

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

packages/cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheetah-grid",
3-
"version": "1.16.2",
3+
"version": "1.16.4",
44
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
55
"keywords": [
66
"spreadsheet",

packages/cheetah-grid/src/js/themes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const builtin: { [key: string]: Theme } = {
1414
};
1515
let defTheme = MATERIAL_DESIGN;
1616

17+
export type { Theme };
18+
1719
export const theme = { Theme };
1820
export function of(
1921
value: ThemeDefine | string | undefined | null

packages/cheetah-grid/src/js/ts-types/grid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface CellRange {
1212
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1313
export type FieldGetter<T> = (record: T) => any;
1414
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15-
export type FieldSetter<T> = (record: T, value: any) => void;
15+
export type FieldSetter<T> = (record: T, value: any) => boolean;
1616
export interface FieldAssessor<T> {
1717
get: FieldGetter<T>;
1818
set: FieldSetter<T>;

packages/vue-cheetah-grid/lib/CGrid.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
>
77
<!--
88
Use this slot to set the simple header definition.
9-
The definition is set to `header` property described in [Define Headers and Columns]
9+
The definition is set to `header` property described in [Define Headers and Columns](https://future-architect.github.io/cheetah-grid/documents/api/js/headers_columns.html)
1010
-->
1111
<slot />
1212
</div>
@@ -16,7 +16,7 @@
1616
<!--
1717
Use this slot to set the layout header definition.
1818
Use this slot in combination with the `layout-body` slot.
19-
The definition is set to `layout.header` property described in [Advanced Layout].
19+
The definition is set to `layout.header` property described in [Advanced Layout](https://future-architect.github.io/cheetah-grid/documents/api/vue/advanced_layout/).
2020
-->
2121
<slot name="layout-header" />
2222
</div>
@@ -26,7 +26,7 @@
2626
<!--
2727
Use this slot to set the layout body definition.
2828
Use this slot in combination with the `layout-header` slot.
29-
The definition is set to `layout.body` property described in [Advanced Layout].
29+
The definition is set to `layout.body` property described in [Advanced Layout](https://future-architect.github.io/cheetah-grid/documents/api/vue/advanced_layout/).
3030
-->
3131
<slot name="layout-body" />
3232
</div>

packages/vue-cheetah-grid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cheetah-grid",
3-
"version": "1.16.3",
3+
"version": "1.16.4",
44
"description": "Cheetah Grid for Vue.js",
55
"main": "lib/index.js",
66
"unpkg": "dist/vueCheetahGrid.js",

packages/vue-cheetah-grid/scripts/lib/metadata.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ const merge = require('./merge')
2525
* @property {string[]} args
2626
* @property {unknown} return
2727
*/
28+
/**
29+
* @typedef {object} ComponentSlotMetadata
30+
* @property {string} name
31+
* @property {string} description
32+
*/
2833
/**
2934
* @typedef {object} ComponentMetadata
3035
* @property {string} name
3136
* @property {string} description
3237
* @property {Keyword[]} keywords
3338
* @property {ComponentPropMetadata[]} props
3439
* @property {ComponentMethodMetadata[]} methods
40+
* @property {ComponentSlotMetadata[]} slots
3541
*/
3642

3743
module.exports = {

packages/vue-cheetah-grid/scripts/vue3-types.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const vue3Emits = Object.keys(EVENT_TYPE)
1010
return r
1111
}, {})
1212

13+
const additionalProperties = {
14+
CGrid:
15+
'rawGrid: cheetahGrid.ListGrid<unknown>;'
16+
}
17+
1318
async function main () {
1419
const allMetadata = await getAllVueComponentMetadata()
1520

@@ -25,17 +30,27 @@ async function main () {
2530
${camelCase(prop.name)}${isRequiredProp(prop) ? '' : '?'}: ${normalizePropType(prop)};
2631
`.trim()
2732
})
28-
const methods = component.methods
29-
.filter(method => method.visibility === 'public')
30-
.map(method => {
31-
return `
33+
const propertyTypes =
34+
[
35+
...component.methods
36+
.filter(method => method.visibility === 'public')
37+
.map(method => {
38+
return `
3239
/** ${method.description} */
3340
${method.name}: ${getMethodSignature(method)};
3441
`.trim()
35-
})
42+
}),
43+
...additionalProperties[componentName] ? [additionalProperties[componentName]] : []
44+
]
3645
const emits = Object.keys(vue3Emits).map(emitName => {
3746
return `
3847
on${pascalCase(emitName)}?: Function;
48+
`.trim()
49+
})
50+
const slots = component.slots.map(prop => {
51+
return `
52+
/** ${prop.description} */
53+
"${prop.name}"?: Slot<{} | undefined>;
3954
`.trim()
4055
})
4156
componentTypes.push(`
@@ -45,7 +60,10 @@ export const ${componentName}: ComponentConstructor<
4560
${indent([...props, ...emits].join('\n'), 4)}
4661
},
4762
{
48-
${indent(methods.join('\n'), 4)}
63+
${indent(propertyTypes.join('\n'), 4)}
64+
},
65+
{
66+
${indent(slots.join('\n'), 4)}
4967
}
5068
>;
5169
`.trim())
@@ -62,17 +80,18 @@ ${componentName}: typeof ${componentName};
6280
fs.mkdirSync(typeDir)
6381
}
6482
fs.writeFileSync(typePath, `${`
65-
import type { PublicProps, ComponentPublicInstance } from "vue";
66-
export * as cheetahGrid from 'cheetah-grid'
83+
import type { PublicProps, ComponentPublicInstance, Slot } from "vue";
84+
import * as cheetahGrid from 'cheetah-grid'
85+
export { cheetahGrid }
6786
export function storeElement (vm: ComponentPublicInstance): void;
6887
export function removeElement (vm: ComponentPublicInstance): void;
6988
export function getComponentFromElement (element: HTMLElement): ComponentPublicInstance | undefined;
7089
71-
type ComponentConstructor<Props = {}, Methods = {}, Slots = {}> = {
90+
type ComponentConstructor<Props = {}, Properties = {}, Slots = {}> = {
7291
new (): {
7392
$props: PublicProps & Props
7493
$slots: Slots
75-
} & Methods
94+
} & Properties
7695
}
7796
7897
${componentTypes.join('\n')}
@@ -83,6 +102,8 @@ ${indent(components.join('\n'), 4)}
83102
}
84103
}
85104
105+
export default CGrid;
106+
86107
export declare function install (Vue: any /* Vue 2 Vue object or Vue 3 App instance */): void;
87108
`.trim()}\n`)
88109

0 commit comments

Comments
 (0)