From 7df5485bf265e50db0ac6dec8a66a7ffd2997d69 Mon Sep 17 00:00:00 2001 From: Moritz Vetter <16950410+Isokaeder@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:22:55 +0200 Subject: [PATCH] refactor(KtTable): use composition API for Table*Cell files --- packages/documentation/tsconfig.json | 1 + .../kotti-ui/source/kotti-table/KtTable.vue | 2 +- .../source/kotti-table/KtTableColumn.ts | 4 +- .../components/TableBodyEmptyRow.ts | 6 +- .../kotti-table/components/TableHeader.vue | 75 ++++---- .../kotti-table/components/TableHeaderCell.ts | 52 ++++-- .../kotti-table/components/TableRowCell.ts | 165 ++++++++++-------- .../kotti-ui/source/kotti-table/constants.ts | 43 ++++- .../kotti-ui/source/kotti-table/mixins.ts | 2 +- packages/kotti-ui/source/kotti-table/types.ts | 12 +- packages/kotti-ui/source/types/kotti.ts | 2 + packages/kotti-ui/source/types/typed-emit.ts | 6 + packages/kotti-ui/tsconfig.json | 7 +- tsconfig.json | 1 + 14 files changed, 243 insertions(+), 135 deletions(-) create mode 100644 packages/kotti-ui/source/types/typed-emit.ts diff --git a/packages/documentation/tsconfig.json b/packages/documentation/tsconfig.json index 5a757fac82..305e74b490 100644 --- a/packages/documentation/tsconfig.json +++ b/packages/documentation/tsconfig.json @@ -23,6 +23,7 @@ "exclude": ["node_modules"], "include": ["./**/*.ts", "./**/*.js", "./**/*.vue"], "vueCompilerOptions": { + "skipTemplateCodegen": true, "strictTemplates": true, "target": 2.7 } diff --git a/packages/kotti-ui/source/kotti-table/KtTable.vue b/packages/kotti-ui/source/kotti-table/KtTable.vue index eedd7cf560..b56ee51201 100644 --- a/packages/kotti-ui/source/kotti-table/KtTable.vue +++ b/packages/kotti-ui/source/kotti-table/KtTable.vue @@ -69,7 +69,7 @@ export default { }, provide() { return { - [KT_TABLE]: this, + [KT_TABLE as symbol]: this, // @ts-expect-error store will exist at runtime [KT_STORE]: this.store, // @ts-expect-error layout will exist at runtime diff --git a/packages/kotti-ui/source/kotti-table/KtTableColumn.ts b/packages/kotti-ui/source/kotti-table/KtTableColumn.ts index a451941019..1ed104bd69 100644 --- a/packages/kotti-ui/source/kotti-table/KtTableColumn.ts +++ b/packages/kotti-ui/source/kotti-table/KtTableColumn.ts @@ -99,7 +99,7 @@ export const KtTableColumn: any = { this.columnConfig = createColumn(this) }, mounted(): void { - const columnIndex = this[KT_TABLE].$children.indexOf(this) + const columnIndex = this[KT_TABLE as symbol].$children.indexOf(this) this[KT_STORE].commit('insertColumn', { column: this.columnConfig, ...(columnIndex !== -1 ? { index: columnIndex } : {}), @@ -120,7 +120,7 @@ function createColumn(column: any = {}) { let columnId = column.id if (!columnId) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - columnId = `${_self[KT_TABLE].tableId}_column_${columnIdSeed}` + columnId = `${_self[KT_TABLE as symbol].tableId}_column_${columnIdSeed}` columnIdSeed++ } // eslint-disable-next-line no-param-reassign diff --git a/packages/kotti-ui/source/kotti-table/components/TableBodyEmptyRow.ts b/packages/kotti-ui/source/kotti-table/components/TableBodyEmptyRow.ts index b1779bb618..8113aba0b0 100644 --- a/packages/kotti-ui/source/kotti-table/components/TableBodyEmptyRow.ts +++ b/packages/kotti-ui/source/kotti-table/components/TableBodyEmptyRow.ts @@ -1,13 +1,13 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { CreateElement, VNode } from 'vue' import { KT_TABLE, KT_STORE, KT_LAYOUT } from '../constants' // eslint-disable-next-line @typescript-eslint/naming-convention -export const TableBodyEmptyRow = { +export const TableBodyEmptyRow: any = { name: 'TableBodyEmptyRow', inject: { KT_TABLE, KT_STORE, KT_LAYOUT }, render(h: CreateElement): VNode { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { colSpan, render } = this as any + const { colSpan, render } = this return h('tr', {}, [ h( 'td', diff --git a/packages/kotti-ui/source/kotti-table/components/TableHeader.vue b/packages/kotti-ui/source/kotti-table/components/TableHeader.vue index f4c082a7bd..737557d176 100644 --- a/packages/kotti-ui/source/kotti-table/components/TableHeader.vue +++ b/packages/kotti-ui/source/kotti-table/components/TableHeader.vue @@ -30,16 +30,7 @@ @dragstart="dragStart($event, column)" @drop="drop($event, column)" > -