-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.ts
More file actions
53 lines (49 loc) · 2.1 KB
/
index.ts
File metadata and controls
53 lines (49 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { computed } from 'vue';
import { defineLayout, useStores } from '@directus/extensions-sdk';
import { formatTitle } from '@directus/format-title';
import LayoutComponent from './src/super-table.vue';
import ActionsComponent from './src/actions.vue';
import OptionsComponent from './src/options.vue';
// Workaround: TS 6.0.2 crashes on complex SDK v17 types in defineLayout() inline objects.
// Extract config to bypass the compiler crash (same fix as expandable-blocks).
const layoutConfig = {
id: 'super-layout-table',
name: 'Super Table',
icon: 'table_rows',
component: LayoutComponent,
slots: {
options: OptionsComponent,
sidebar: () => null,
actions: ActionsComponent,
},
headerShadow: false,
setup(props: any, { emit }: any) {
const { useFieldsStore } = useStores();
const fieldsStore = useFieldsStore();
// Issue #48: Expose a flat list of currently visible columns to slot
// components (options sidebar). Each entry uses the *root* field key as id
// (translations.title rather than translations.title:de-DE) so all
// language variants of the same root field share a single override entry.
// Multiple language columns of the same root collapse into one picker entry.
const availableFieldChoices = computed(() => {
const layoutFields: string[] = props.layoutQuery?.fields ?? [];
const customFieldNames: Record<string, string> = props.layoutOptions?.customFieldNames ?? {};
const seen = new Map<string, { key: string; label: string }>();
for (const key of layoutFields) {
const rootKey = key.includes(':') ? key.split(':')[0] : key;
if (seen.has(rootKey)) continue;
const root = rootKey.split('.')[0];
const fieldData = fieldsStore.getField(props.collection, root);
const fallbackName = fieldData?.name ?? formatTitle(rootKey);
seen.set(rootKey, { key: rootKey, label: customFieldNames[key] ?? fallbackName });
}
return Array.from(seen.values());
});
return {
...props,
emit,
availableFieldChoices,
};
},
} as any;
export default defineLayout(layoutConfig);