refactor(editor): Fix typecheck for design-system and chat packages (no-changelog) (#9599)

This commit is contained in:
Alex Grozav 2024-06-03 16:04:21 +03:00 committed by GitHub
parent 485838446f
commit 1a982d51b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 81 additions and 60 deletions

View file

@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { config } from '@vue/test-utils';
import { N8nPlugin } from '@/plugin';
import { N8nPlugin } from 'n8n-design-system/plugin';
config.global.plugins = [N8nPlugin];

View file

@ -40,7 +40,7 @@ import N8nButton from '../N8nButton';
import N8nHeading from '../N8nHeading';
import N8nText from '../N8nText';
import N8nCallout, { type CalloutTheme } from '../N8nCallout';
import type { ButtonType } from '@/types/button';
import type { ButtonType } from 'n8n-design-system/types/button';
interface ActionBoxProps {
emoji: string;

View file

@ -62,7 +62,7 @@ import { ElDropdown, ElDropdownMenu, ElDropdownItem, type Placement } from 'elem
import N8nIcon from '../N8nIcon';
import { N8nKeyboardShortcut } from '../N8nKeyboardShortcut';
import type { ActionDropdownItem } from '../../types';
import type { IconSize } from '@/types/icon';
import type { IconSize } from 'n8n-design-system/types/icon';
const TRIGGER = ['click', 'hover'] as const;

View file

@ -43,9 +43,9 @@
<script lang="ts" setup>
import { ElDropdown, ElDropdownMenu, ElDropdownItem, type Placement } from 'element-plus';
import type { UserAction } from '@/types';
import type { UserAction } from 'n8n-design-system/types';
import N8nIcon from '../N8nIcon';
import type { IconOrientation, IconSize } from '@/types/icon';
import type { IconOrientation, IconSize } from 'n8n-design-system/types/icon';
const SIZE = ['mini', 'small', 'medium'] as const;
const THEME = ['default', 'dark'] as const;

View file

@ -7,7 +7,7 @@
</template>
<script lang="ts" setup>
import type { TextSize } from '@/types/text';
import type { TextSize } from 'n8n-design-system/types/text';
import N8nText from '../N8nText';
const THEME = [

View file

@ -26,7 +26,7 @@
import { useCssModule, computed, useAttrs, watchEffect } from 'vue';
import N8nIcon from '../N8nIcon';
import N8nSpinner from '../N8nSpinner';
import type { ButtonProps } from '@/types/button';
import type { ButtonProps } from 'n8n-design-system/types/button';
const $style = useCssModule();
const $attrs = useAttrs();

View file

@ -19,12 +19,12 @@
import { computed, useCssModule } from 'vue';
import N8nText from '../N8nText';
import N8nIcon from '../N8nIcon';
import type { IconSize } from '@/types/icon';
import type { IconSize } from 'n8n-design-system/types/icon';
const THEMES = ['info', 'success', 'secondary', 'warning', 'danger', 'custom'] as const;
export type CalloutTheme = (typeof THEMES)[number];
const CALLOUT_DEFAULT_ICONS = {
const CALLOUT_DEFAULT_ICONS: Record<string, string> = {
info: 'info-circle',
success: 'check-circle',
warning: 'exclamation-triangle',

View file

@ -23,6 +23,7 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { ElCheckbox } from 'element-plus';
import type { CheckboxValueType } from 'element-plus';
import N8nInputLabel from '../N8nInputLabel';
const LABEL_SIZE = ['small', 'medium'] as const;
@ -44,8 +45,10 @@ withDefaults(defineProps<CheckboxProps>(), {
labelSize: 'medium',
});
const $emit = defineEmits(['update:modelValue']);
const onUpdateModelValue = (value: boolean) => $emit('update:modelValue', value);
const $emit = defineEmits<{
(event: 'update:modelValue', value: CheckboxValueType): void;
}>();
const onUpdateModelValue = (value: CheckboxValueType) => $emit('update:modelValue', value);
const checkbox = ref<InstanceType<typeof ElCheckbox>>();
const onLabelClick = () => {

View file

@ -36,12 +36,12 @@ const colorPickerProps = computed(() => {
});
const emit = defineEmits<{
(event: 'update:modelValue', value: string): void;
(event: 'change', value: string): void;
(event: 'active-change', value: string): void;
(event: 'update:modelValue', value: string | null): void;
(event: 'change', value: string | null): void;
(event: 'active-change', value: string | null): void;
}>();
const onChange = (value: string) => {
const onChange = (value: string | null) => {
emit('change', value);
};
@ -49,11 +49,11 @@ const onInput = (value: string) => {
color.value = value;
};
const onActiveChange = (value: string) => {
const onActiveChange = (value: string | null) => {
emit('active-change', value);
};
const onColorSelect = (value: string) => {
const onColorSelect = (value: string | null) => {
emit('update:modelValue', value);
};
</script>

View file

@ -43,7 +43,7 @@ import N8nFormInputs from '../N8nFormInputs';
import N8nHeading from '../N8nHeading';
import N8nLink from '../N8nLink';
import N8nButton from '../N8nButton';
import type { IFormInput } from '@/types';
import type { IFormInput } from 'n8n-design-system/types';
import { createEventBus } from '../../utils';
interface FormBoxProps {

View file

@ -126,7 +126,7 @@ export default defineComponent({
onUpdateModelValue(name: string, value: unknown) {
this.values = {
...this.values,
[name]: value,
[name]: value as Validatable,
};
this.$emit('update', { name, value });
this.$emit('update:modelValue', this.values);

View file

@ -7,7 +7,7 @@
<script lang="ts" setup>
import type { FontAwesomeIconProps } from '@fortawesome/vue-fontawesome';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import type { IconSize, IconColor } from '@/types/icon';
import type { IconSize, IconColor } from 'n8n-design-system/types/icon';
import N8nText from '../N8nText';
interface IconProps {

View file

@ -3,7 +3,7 @@
</template>
<script lang="ts" setup>
import type { IconButtonProps } from '@/types/button';
import type { IconButtonProps } from 'n8n-design-system/types/button';
import N8nButton from '../N8nButton';
defineOptions({ name: 'N8nIconButton' });

View file

@ -42,7 +42,7 @@
import { onMounted, ref } from 'vue';
import N8nText from '../N8nText';
import N8nIcon from '../N8nIcon';
import type { IconColor } from '@/types/icon';
import type { IconColor } from 'n8n-design-system/types/icon';
import { createEventBus, type EventBus } from '../../utils';
interface IAccordionItem {

View file

@ -34,8 +34,8 @@
import { computed, ref } from 'vue';
import { ElInput } from 'element-plus';
import { uid } from '../../utils';
import type { InputSize, InputType } from '@/types/input';
import type { ElementPlusSizePropType, InputAutocompletePropType } from '@/types';
import type { InputSize, InputType } from 'n8n-design-system/types/input';
import type { ElementPlusSizePropType, InputAutocompletePropType } from 'n8n-design-system/types';
interface InputProps {
modelValue?: string | number;

View file

@ -49,7 +49,7 @@
import N8nText from '../N8nText';
import N8nIcon from '../N8nIcon';
import N8nTooltip from '../N8nTooltip';
import type { TextColor } from '@/types/text';
import type { TextColor } from 'n8n-design-system/types/text';
const SIZE = ['small', 'medium'] as const;

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import type { ElementPlusSizePropType, InputSize } from '@/types';
import type { ElementPlusSizePropType, InputSize } from 'n8n-design-system/types';
import { ElInputNumber } from 'element-plus';
import { computed } from 'vue';

View file

@ -12,7 +12,7 @@
import type { RouteLocationRaw } from 'vue-router';
import N8nText from '../N8nText';
import N8nRoute from '../N8nRoute';
import type { TextSize } from '@/types/text';
import type { TextSize } from 'n8n-design-system/types/text';
const THEME = ['primary', 'danger', 'text', 'secondary'] as const;

View file

@ -114,7 +114,7 @@ const htmlContent = computed(() => {
}
const html = md.render(escapeMarkdown(contentToRender));
const safeHtml = xss(html, {
onTagAttr: (tag, name, value) => {
onTagAttr(tag, name, value) {
if (tag === 'img' && name === 'src') {
if (value.match(fileIdRegex)) {
const id = value.split('fileId:')[1];
@ -129,18 +129,21 @@ const htmlContent = computed(() => {
}
}
// Return nothing, means keep the default handling measure
return;
},
onTag(tag, code) {
if (tag === 'img' && code.includes('alt="workflow-screenshot"')) {
return '';
}
// return nothing, keep tag
return;
},
onIgnoreTag(tag, tagHTML) {
// Allow checkboxes
if (tag === 'input' && tagHTML.includes('type="checkbox"')) {
return tagHTML;
}
return;
},
whiteList: xssWhiteList,
});

View file

@ -83,8 +83,8 @@ const props = withDefaults(defineProps<MenuProps>(), {
const $route = useRoute();
const $emit = defineEmits<{
(event: 'select', itemId: string);
(event: 'update:modelValue', itemId: string);
(event: 'select', itemId: string): void;
(event: 'update:modelValue', itemId: string): void;
}>();
const activeTab = ref(props.modelValue);

View file

@ -1,4 +1,4 @@
import type { IMenuItem } from '@/types';
import type { IMenuItem } from 'n8n-design-system/types';
import type { RouteLocationNormalizedLoaded, RouteLocationRaw } from 'vue-router';
/**

View file

@ -1,6 +1,6 @@
import { render } from '@testing-library/vue';
import N8nNotice from '../Notice.vue';
import { N8nText } from '@/components';
import { N8nText } from 'n8n-design-system/components';
describe('components', () => {
describe('N8nNotice', () => {

View file

@ -80,9 +80,9 @@ export interface ResizeData {
}
const $emit = defineEmits<{
(event: 'resizestart');
(event: 'resizestart'): void;
(event: 'resize', value: ResizeData): void;
(event: 'resizeend');
(event: 'resizeend'): void;
}>();
const enabledDirections = computed((): Direction[] => {
@ -165,7 +165,7 @@ const resizerMove = (event: MouseEvent) => {
state.dir.value = targetResizer.dataset.dir.toLocaleLowerCase() as Direction;
}
document.body.style.cursor = directionsCursorMaps[state.dir.value];
document.body.style.cursor = directionsCursorMaps[state.dir.value as Direction];
state.x.value = event.pageX;
state.y.value = event.pageY;

View file

@ -31,7 +31,7 @@
<script lang="ts">
import { ElSelect } from 'element-plus';
import { type PropType, defineComponent } from 'vue';
import type { SelectSize } from '@/types';
import type { SelectSize } from 'n8n-design-system/types';
import { isEventBindingElementAttribute } from '../../utils';
type InnerSelectRef = InstanceType<typeof ElSelect>;

View file

@ -11,7 +11,7 @@
</template>
<script lang="ts" setup>
import type { TextSize } from '@/types/text';
import type { TextSize } from 'n8n-design-system/types/text';
import N8nIcon from '../N8nIcon';
const TYPE = ['dots', 'ring'] as const;

View file

@ -94,12 +94,12 @@ const props = withDefaults(defineProps<StickyProps>(), {
});
const $emit = defineEmits<{
(event: 'edit', editing: boolean);
(event: 'update:modelValue', value: string);
(event: 'markdown-click', link: string, e: Event);
(event: 'resize', values: ResizeData);
(event: 'resizestart');
(event: 'resizeend');
(event: 'edit', editing: boolean): void;
(event: 'update:modelValue', value: string): void;
(event: 'markdown-click', link: string, e: Event): void;
(event: 'resize', values: ResizeData): void;
(event: 'resizestart'): void;
(event: 'resizeend'): void;
}>();
const { t } = useI18n();

View file

@ -112,7 +112,7 @@ onUnmounted(() => {
const $emit = defineEmits<{
(event: 'tooltipClick', tab: string, e: MouseEvent): void;
(event: 'update:modelValue', tab: string);
(event: 'update:modelValue', tab: string): void;
}>();
const handleTooltipClick = (tab: string, event: MouseEvent) => $emit('tooltipClick', tab, event);

View file

@ -6,7 +6,7 @@
<script lang="ts" setup>
import { computed, useCssModule } from 'vue';
import type { TextSize, TextColor, TextAlign } from '@/types/text';
import type { TextSize, TextColor, TextAlign } from 'n8n-design-system/types/text';
interface TextProps {
bold?: boolean;

View file

@ -24,7 +24,7 @@
import type { PropType } from 'vue';
import { defineComponent } from 'vue';
import { ElTooltip } from 'element-plus';
import type { IN8nButton } from '@/types';
import type { IN8nButton } from 'n8n-design-system/types';
import N8nButton from '../N8nButton';
export default defineComponent({

View file

@ -1,5 +1,5 @@
<template>
<div class="n8n-tree">
<div v-if="isObject(value)" class="n8n-tree">
<div v-for="(label, i) in Object.keys(value)" :key="i" :class="classes">
<div v-if="isSimple(value[label])" :class="$style.simple">
<slot v-if="$slots.label" name="label" :label="label" :path="getPath(label)" />
@ -14,7 +14,7 @@
<n8n-tree
:path="getPath(label)"
:depth="depth + 1"
:value="value[label]"
:value="value[label] as Record<string, unknown>"
:node-class="nodeClass"
>
<template v-for="(_, name) in $slots" #[name]="data">
@ -30,12 +30,20 @@
import { computed, useCssModule } from 'vue';
interface TreeProps {
value?: unknown;
value?: Record<string, unknown>;
path?: Array<string | number>;
depth?: number;
nodeClass?: string;
}
defineSlots<{
[key: string]: (props: {
label?: string;
path?: Array<string | number>;
value?: unknown;
}) => never;
}>();
defineOptions({ name: 'N8nTree' });
const props = withDefaults(defineProps<TreeProps>(), {
value: () => ({}),
@ -49,6 +57,10 @@ const classes = computed((): Record<string, boolean> => {
return { [props.nodeClass]: !!props.nodeClass, [$style.indent]: props.depth > 0 };
});
const isObject = (data: unknown): data is Record<string, unknown> => {
return typeof data === 'object' && data !== null;
};
const isSimple = (data: unknown): boolean => {
if (data === null || data === undefined) {
return true;

View file

@ -1,5 +1,5 @@
<script lang="ts" setup>
import type { IUser, UserStackGroups } from '@/types';
import type { IUser, UserStackGroups } from 'n8n-design-system/types';
import N8nAvatar from '../N8nAvatar';
import N8nUserInfo from '../N8nUserInfo';
import type { PropType } from 'vue';

View file

@ -1,6 +1,6 @@
import { render } from '@testing-library/vue';
import UserStack from '../UserStack.vue';
import { N8nAvatar, N8nUserInfo } from '@/main';
import { N8nAvatar, N8nUserInfo } from 'n8n-design-system/main';
describe('UserStack', () => {
it('should render flat user list', () => {

View file

@ -1,7 +1,7 @@
import N8nUsersList from './UsersList.vue';
import { action } from '@storybook/addon-actions';
import type { StoryFn } from '@storybook/vue3';
import type { IUser } from '@/types';
import type { IUser } from 'n8n-design-system/types';
export default {
title: 'Modules/UsersList',

View file

@ -1,4 +1,4 @@
import { useDeviceSupport } from '@/composables/useDeviceSupport';
import { useDeviceSupport } from 'n8n-design-system/composables/useDeviceSupport';
describe('useDeviceSupport()', () => {
beforeEach(() => {

View file

@ -1,6 +1,6 @@
import defaultLang from '../locale/lang/en';
import createFormatTemplate from './format';
import type { N8nLocale, N8nLocaleTranslateFn } from '@/types';
import type { N8nLocale, N8nLocaleTranslateFn } from 'n8n-design-system/types';
// import { ElementLocale } from 'element-plus';
// import ElementLang from 'element-plus/lib/locale/lang/en';

View file

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { N8nLocale } from '@/types';
import type { N8nLocale } from 'n8n-design-system/types';
export default {
'nds.auth.roles.owner': 'Owner',

View file

@ -1,4 +1,4 @@
import type { KeyboardShortcut } from '@/types/keyboardshortcut';
import type { KeyboardShortcut } from 'n8n-design-system/types/keyboardshortcut';
export interface ActionDropdownItem {
id: string;

View file

@ -1,4 +1,4 @@
import { getValueByPath } from '@/utils';
import { getValueByPath } from 'n8n-design-system/utils';
describe('getValueByPath()', () => {
const object = {

View file

@ -13,7 +13,7 @@
"types": ["vitest/globals"],
"typeRoots": ["./node_modules/@testing-library", "./node_modules/@types", "../../node_modules", "../../node_modules/@types"],
"paths": {
"@/*": ["src/*"]
"n8n-design-system/*": ["./src/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"],
// TODO: remove all options below this line

View file

@ -13,13 +13,16 @@
"baseUrl": ".",
"types": [
"vitest/globals",
"unplugin-icons/types/vue",
"./src/shims.d.ts",
"./src/shims-vue.d.ts",
"./src/v3-infinite-loading.d.ts",
"../workflow/src/types.d.ts"
"../workflow/src/types.d.ts",
"../design-system/src/shims-markdown-it.d.ts"
],
"paths": {
"@/*": ["src/*"],
"@/*": ["./src/*"],
"n8n-design-system": ["../design-system/src/main.ts"],
"n8n-design-system/*": ["../design-system/src/*"],
"@n8n/chat/*": ["../@n8n/chat/src/*"]
},