Skip to content

Commit 7abfc37

Browse files
Seungwoo321claude
andcommitted
feat: add TypeScript support to pivottable components
- Convert pivottable Vue components to use TypeScript - Add type definitions for props and component interfaces - Update composables with proper type annotations - Remove obsolete utilities.d.ts file - Refactor defaultProps structure for better type safety 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2aee633 commit 7abfc37

26 files changed

+104
-261
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"clean": "rimraf dist",
5555
"clean:all": "rimraf dist packages/*/dist",
5656
"dev": "vite",
57-
"build": "tsc src/helper/utilities.ts --declaration --emitDeclarationOnly --outDir src/helper && vite build",
57+
"build": "vite build",
5858
"preview": "vite preview",
5959
"lint": "eslint",
6060
"build:all": "pnpm clean && pnpm build && pnpm -r --filter './packages/*' build",

src/components/pivottable-ui/VAggregatorCell.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</td>
3939
</template>
4040

41-
<script setup>
41+
<script setup lang="ts">
4242
import { computed } from 'vue'
4343
import VDropdown from './VDropdown.vue'
4444

src/components/pivottable-ui/VPivottableUi.vue

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -131,52 +131,44 @@
131131
</table>
132132
</template>
133133

134-
<script setup>
135-
import { defaultProps, PivotData, sortAs } from '@/helper'
134+
<script setup lang="ts">
135+
import { aggregators, PivotData, sortAs } from '@/helper'
136136
import VRendererCell from './VRendererCell.vue'
137137
import VAggregatorCell from './VAggregatorCell.vue'
138138
import VDragAndDropCell from './VDragAndDropCell.vue'
139139
import VPivottable from '../pivottable/VPivottable.vue'
140-
import TableRenderer from '../pivottable/renderer/index'
141140
import { computed, watch } from 'vue'
142141
import {
143142
usePropsState,
144143
useMaterializeInput,
145144
usePivotUiState,
146145
provideFilterBox
147146
} from '@/composables'
147+
import { DefaultPropsType } from '@/types'
148148
149-
const props = defineProps({
150-
...defaultProps,
151-
hiddenAttributes: {
152-
type: Array,
153-
default: () => []
154-
},
155-
hiddenFromAggregators: {
156-
type: Array,
157-
default: () => []
158-
},
159-
hiddenFromDragDrop: {
160-
type: Array,
161-
default: () => []
162-
},
163-
restrictedFromDragDrop: {
164-
type: Array,
165-
default: () => []
166-
},
167-
menuLimit: {
168-
type: Number,
169-
default: 500
170-
},
171-
pivotModel: {
172-
type: Object,
173-
default: () => ({})
174-
},
175-
hideFilterBoxOfUnusedAttributes: {
176-
type: Boolean,
177-
default: false
149+
const props = withDefaults(
150+
defineProps<
151+
DefaultPropsType & {
152+
hiddenAttributes?: string[]
153+
hiddenFromAggregators?: string[]
154+
hiddenFromDragDrop?: string[]
155+
restrictedFromDragDrop?: string[]
156+
menuLimit?: number
157+
pivotModel?: any
158+
hideFilterBoxOfUnusedAttributes?: boolean
159+
}
160+
>(),
161+
{
162+
aggregators: () => aggregators,
163+
hiddenAttributes: () => [],
164+
hiddenFromAggregators: () => [],
165+
hiddenFromDragDrop: () => [],
166+
restrictedFromDragDrop: () => [],
167+
menuLimit: 500,
168+
hideFilterBoxOfUnusedAttributes: false
178169
}
179-
})
170+
)
171+
180172
const {
181173
state,
182174
localeStrings,
@@ -205,7 +197,7 @@ const { allFilters, materializedInput } = useMaterializeInput(
205197
)
206198
207199
const rendererItems = computed(() =>
208-
Object.keys(state.renderers).length ? state.renderers : TableRenderer
200+
Object.keys(state.renderers).length ? state.renderers : {}
209201
)
210202
const aggregatorItems = computed(() => state.aggregators)
211203
const rowAttrs = computed(() => {
@@ -238,7 +230,7 @@ const unusedAttrs = computed(() => {
238230
!state.hiddenAttributes.includes(e) &&
239231
!state.hiddenFromDragDrop.includes(e)
240232
)
241-
.sort(sortAs(state.unusedOrder))
233+
.sort(sortAs(pivotUiState.unusedOrder))
242234
})
243235
244236
const pivotData = computed(() => new PivotData(state))
@@ -264,12 +256,13 @@ const pivotProps = computed(() => ({
264256
rowOrder: state.rowOrder,
265257
colOrder: state.colOrder,
266258
tableMaxWidth: state.tableMaxWidth,
267-
localeStrings: localeStrings.value
259+
localeStrings: localeStrings.value,
260+
menuLimit: props.menuLimit
268261
}))
269262
270-
onUpdateUnusedOrder(props.unusedAttrs)
263+
onUpdateUnusedOrder(unusedAttrs.value)
271264
272-
provideFilterBox(props)
265+
provideFilterBox(pivotProps.value)
273266
274267
watch(
275268
[allFilters, materializedInput],

src/components/pivottable-ui/VRendererCell.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const rendererOptions = computed<string[]>(() =>
2525
2626
interface RendererDefinition {
2727
name: string
28-
props: Record<string, any>
28+
props?: Record<string, any>
2929
setup: (props: any) => () => VNode
3030
}
3131

src/components/pivottable/VPivottableBody.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
</template>
2020

2121
<script setup lang="ts">
22-
import { useProvidePivotData } from '@/composables/useProvidePivotData'
22+
import { useProvidePivotData } from '@/composables'
2323
import VPivottableBodyRows from './VPivottableBodyRows.vue'
2424
import VPivottableBodyRowsTotalRow from './VPivottableBodyRowsTotalRow.vue'
2525
import type { DefaultPropsType } from '@/types'
2626
27-
type Props = Pick<DefaultPropsType, 'showRowTotal' | 'showColTotal' | 'languagePack' | 'tableOptions'>
27+
type Props = Pick<
28+
DefaultPropsType,
29+
'showRowTotal' | 'showColTotal' | 'languagePack' | 'tableOptions'
30+
>
2831
2932
defineProps<Props>()
3033

src/components/pivottable/VPivottableBodyRows.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</template>
5050

5151
<script setup lang="ts">
52-
import { useProvidePivotData } from '@/composables/useProvidePivotData'
52+
import { useProvidePivotData } from '@/composables'
5353
import { DefaultPropsType } from '@/types'
5454
5555
type VPivottableBodyRowsProps = Pick<
@@ -86,20 +86,20 @@ const handleCellClick = (value: any, rowValues: any, colValues: any) => {
8686
if (props.tableOptions?.clickCallback) {
8787
const filters = {} as any
8888
89-
colAttrs.value.forEach((attr, i) => {
89+
colAttrs.value.forEach((attr: string, i: number) => {
9090
if (colValues[i] !== undefined && colValues[i] !== null) {
9191
filters[attr] = colValues[i]
9292
}
9393
})
9494
95-
rowAttrs.value.forEach((attr, i) => {
95+
rowAttrs.value.forEach((attr: string, i: number) => {
9696
if (rowValues[i] !== undefined && rowValues[i] !== null) {
9797
filters[attr] = rowValues[i]
9898
}
9999
})
100100
101101
return (event: MouseEvent) =>
102-
props.tableOptions.clickCallback(event, value, filters, pivotData.value)
102+
props.tableOptions?.clickCallback(event, value, filters, pivotData.value)
103103
}
104104
return () => ({})
105105
}

src/components/pivottable/VPivottableBodyRowsTotalRow.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class="pvtTotalLabel"
55
:colSpan="rowAttrs.length + (colAttrs.length === 0 ? 0 : 1)"
66
>
7-
{{ languagePack.totals }}
7+
{{ languagePack?.totals }}
88
</th>
99
<td
1010
v-for="(colKey, i) in colKeys"
@@ -29,7 +29,7 @@
2929

3030
<script setup lang="ts">
3131
import { computed } from 'vue'
32-
import { useProvidePivotData } from '@/composables/useProvidePivotData'
32+
import { useProvidePivotData } from '@/composables'
3333
import { DefaultPropsType } from '@/types'
3434
3535
type VPivottableBodyRowsTotalRowProps = Pick<
@@ -61,20 +61,20 @@ const handleCellClick = (value: any, rowValues: any[], colValues: any[]) => {
6161
if (props.tableOptions?.clickCallback) {
6262
const filters = {} as any
6363
64-
colAttrs.value.forEach((attr, i) => {
64+
colAttrs.value.forEach((attr: string, i: number) => {
6565
if (colValues[i] !== undefined && colValues[i] !== null) {
6666
filters[attr] = colValues[i]
6767
}
6868
})
6969
70-
rowAttrs.value.forEach((attr, i) => {
70+
rowAttrs.value.forEach((attr: string, i: number) => {
7171
if (rowValues[i] !== undefined && rowValues[i] !== null) {
7272
filters[attr] = rowValues[i]
7373
}
7474
})
7575
7676
return (event: MouseEvent) =>
77-
props.tableOptions.clickCallback(event, value, filters, pivotData.value)
77+
props.tableOptions?.clickCallback(event, value, filters, pivotData.value)
7878
}
7979
return () => ({})
8080
}

src/components/pivottable/VPivottableHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</template>
3737

3838
<script setup lang="ts">
39-
import { useProvidePivotData } from '@/composables/useProvidePivotData'
39+
import { useProvidePivotData } from '@/composables'
4040
import VPivottableHeaderColumns from './VPivottableHeaderColumns.vue'
4141
import VPivottableHeaderRows from './VPivottableHeaderRows.vue'
4242
import VPivottableHeaderRowsTotal from './VPivottableHeaderRowsTotal.vue'

src/components/pivottable/VPivottableHeaderColumns.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</template>
1616

1717
<script setup lang="ts">
18-
import { useProvidePivotData } from '@/composables/useProvidePivotData'
18+
import { useProvidePivotData } from '@/composables'
1919
2020
type VPivottableHeaderColumnsProps = {
2121
colKeys: string[][]

src/components/pivottable/VPivottableHeaderRows.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class="pvtTotalLabel"
1212
v-if="showRowTotal || colAttrsLength !== 0"
1313
>
14-
{{ colAttrsLength === 0 && showRowTotal ? languagePack.totals : null }}
14+
{{ colAttrsLength === 0 && showRowTotal ? languagePack?.totals : null }}
1515
</th>
1616
</tr>
1717
</template>

0 commit comments

Comments
 (0)