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 01/13] 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)"
>
-
+
From 25825aa4ef171a24d6277f1e3ec4a2bc4f0369d6 Mon Sep 17 00:00:00 2001
From: Moritz Vetter <16950410+Isokaeder@users.noreply.github.com>
Date: Mon, 22 Jul 2024 15:56:00 +0200
Subject: [PATCH 03/13] version(kotti-ui@6.1.0): Composition API for some kotti
table subcomponents
---
packages/kotti-ui/package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/kotti-ui/package.json b/packages/kotti-ui/package.json
index 48073b31f7..58ba9d2a80 100644
--- a/packages/kotti-ui/package.json
+++ b/packages/kotti-ui/package.json
@@ -96,5 +96,5 @@
"style": "./dist/style.css",
"type": "module",
"types": "./dist/index.d.ts",
- "version": "6.0.1"
+ "version": "6.1.0"
}
From 2d3d100fa106740d731535a08b151b52b1ec475d Mon Sep 17 00:00:00 2001
From: Moritz Vetter <16950410+Isokaeder@users.noreply.github.com>
Date: Tue, 23 Jul 2024 09:36:52 +0200
Subject: [PATCH 04/13] version(kotti-ui@6.1.1): externalize translations
create helper function to handle eventual default keys when importing element-ui's translation objects
---
packages/kotti-ui/package.json | 2 +-
packages/kotti-ui/source/kotti-i18n/hooks.ts | 69 +++++++++++++++-----
packages/kotti-ui/vite.config.ts | 2 +-
3 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/packages/kotti-ui/package.json b/packages/kotti-ui/package.json
index 58ba9d2a80..3462beb148 100644
--- a/packages/kotti-ui/package.json
+++ b/packages/kotti-ui/package.json
@@ -96,5 +96,5 @@
"style": "./dist/style.css",
"type": "module",
"types": "./dist/index.d.ts",
- "version": "6.1.0"
+ "version": "6.1.1"
}
diff --git a/packages/kotti-ui/source/kotti-i18n/hooks.ts b/packages/kotti-ui/source/kotti-i18n/hooks.ts
index a137d8189f..90430e8d29 100644
--- a/packages/kotti-ui/source/kotti-i18n/hooks.ts
+++ b/packages/kotti-ui/source/kotti-i18n/hooks.ts
@@ -1,9 +1,4 @@
import elementLocale from 'element-ui/lib/locale/index.js'
-import elementDe from 'element-ui/lib/locale/lang/de.js'
-import elementEn from 'element-ui/lib/locale/lang/en.js'
-import elementEs from 'element-ui/lib/locale/lang/es.js'
-import elementFr from 'element-ui/lib/locale/lang/fr.js'
-import elementJa from 'element-ui/lib/locale/lang/ja.js'
import type { Ref, UnwrapRef } from 'vue'
import { computed, inject, provide, reactive, watch } from 'vue'
@@ -59,6 +54,37 @@ export const useTranslationNamespace =
(
return computed(() => context.messages[namespace])
}
+interface DefaultObject> {
+ default: DefaultObject | R
+}
+
+/**
+ * HACK: This function works around a CJS/ESM/EsModule interop issue.
+ *
+ * The objects we import at `element-ui/lib/locale/lang/[a-z]{2}.js` are EsModules
+ * (exports.__esModule = true). Due to current javascript flavour shenanigans,
+ * the imported object that we need can be found at the root, at the `.default` key,
+ * or even at the `.default.default` key.
+ * To mitigate we iterate down the potential default chain until we arrive at the
+ * right position.
+ */
+const accessDefaultKey = >(
+ obj: DefaultObject,
+): R => {
+ if (!('default' in obj)) return obj
+
+ let current: DefaultObject | R = obj
+
+ // Practically, this should terminate after at most 2 iterations. Make it 10 for good measure
+ for (let i = 0; i < 10; i++) {
+ current = current.default as DefaultObject | R
+ if (!('default' in current)) {
+ return current
+ }
+ }
+ throw new Error('accessDefaultKey: could not exhaust nested default keys')
+}
+
/**
* Provides the translation context to child components
*/
@@ -89,19 +115,26 @@ export const useI18nProvide = ({
*/
watch(
locale,
- (newValue) => {
- const elementUiTranslations = {
- 'en-US': elementEn,
- 'de-DE': elementDe,
- 'es-ES': elementEs,
- 'fr-FR': elementFr,
- 'ja-JP': elementJa,
- }[newValue]
-
- if ('default' in elementUiTranslations)
- throw new Error('Detected Broken Build')
-
- elementLocale.use(elementUiTranslations)
+ async (newValue) => {
+ try {
+ const elementUiTranslations = await {
+ /* eslint-disable @typescript-eslint/naming-convention */
+ 'en-US': () => import('element-ui/lib/locale/lang/en.js'),
+ 'de-DE': () => import('element-ui/lib/locale/lang/de.js'),
+ 'es-ES': () => import('element-ui/lib/locale/lang/es.js'),
+ 'fr-FR': () => import('element-ui/lib/locale/lang/fr.js'),
+ 'ja-JP': () => import('element-ui/lib/locale/lang/ja.js'),
+ /* eslint-enable @typescript-eslint/naming-convention */
+ }[newValue]()
+
+ const resolvedEsModuleInterop = accessDefaultKey(elementUiTranslations)
+
+ elementLocale.use(resolvedEsModuleInterop)
+ } catch (error) {
+ // eslint-disable-next-line no-console
+ console.error(error)
+ throw error
+ }
},
{ immediate: true, flush: 'post' },
)
diff --git a/packages/kotti-ui/vite.config.ts b/packages/kotti-ui/vite.config.ts
index e81cdb5b88..cfeaeb58ae 100644
--- a/packages/kotti-ui/vite.config.ts
+++ b/packages/kotti-ui/vite.config.ts
@@ -56,7 +56,7 @@ export default defineConfig(({ mode }) => {
const external = [
...Object.keys(packageJSON.peerDependencies),
...Object.keys(packageJSON.dependencies),
- /.*element-ui\/lib\/date-picker.js.*/,
+ /.*element-ui.*/,
/.*tippy\.js.*/,
/lodash\/.*/,
/vue\/.*/,
From 55d2c71a5537bf0a1ed6b1a5e57b14d689970476 Mon Sep 17 00:00:00 2001
From: Moritz Vetter <16950410+Isokaeder@users.noreply.github.com>
Date: Wed, 24 Jul 2024 17:27:33 +0200
Subject: [PATCH 05/13] refactor(KtTable): use Composition API in
TableHeader.vue
Co-Authored-By: Florian Wendelborn <1133858+FlorianWendelborn@users.noreply.github.com>
---
.../kotti-ui/source/kotti-table/KtTable.vue | 2 +-
.../kotti-table/components/TableHeader.vue | 263 +++++++-----------
.../kotti-table/components/TableRowCell.ts | 1 +
.../kotti-ui/source/kotti-table/constants.ts | 13 +-
.../source/kotti-table/logic/column.ts | 119 ++++----
.../source/kotti-table/logic/select.ts | 1 +
.../source/kotti-table/logic/types.ts | 13 +-
packages/kotti-ui/source/kotti-table/types.ts | 10 +-
8 files changed, 191 insertions(+), 231 deletions(-)
diff --git a/packages/kotti-ui/source/kotti-table/KtTable.vue b/packages/kotti-ui/source/kotti-table/KtTable.vue
index 0404162888..96c4ed1229 100644
--- a/packages/kotti-ui/source/kotti-table/KtTable.vue
+++ b/packages/kotti-ui/source/kotti-table/KtTable.vue
@@ -53,7 +53,7 @@ export const INITIAL_TABLE_STORE_PROPS = [
'sortable',
'sortedColumns',
'sortMultiple',
-]
+] as const
export default {
name: 'KtTable',
diff --git a/packages/kotti-ui/source/kotti-table/components/TableHeader.vue b/packages/kotti-ui/source/kotti-table/components/TableHeader.vue
index 737557d176..9e11220bcd 100644
--- a/packages/kotti-ui/source/kotti-table/components/TableHeader.vue
+++ b/packages/kotti-ui/source/kotti-table/components/TableHeader.vue
@@ -3,7 +3,7 @@
|
- |
-
-
- triangle_up
- triangle_down
+
+
+
+ triangle_up
+
+
+ triangle_down
+
|
@@ -51,146 +47,102 @@