Skip to content

Commit

Permalink
Merge pull request #296 from ckeditor/fix-typings
Browse files Browse the repository at this point in the history
Fix: Fix the component properties and event types.

Internal: Add `tsconfig.json` to the demo.

Internal: Lint only the `.ts` and `.vue` files.
  • Loading branch information
pomek authored Jul 17, 2024
2 parents 88bea11 + 893998c commit e2a9bbc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
11 changes: 11 additions & 0 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": [
"../src/plugin.ts"
]
},
"include": [
"**/*"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
"test": "vitest run --coverage",
"test:watch": "vitest --ui --watch",
"lint": "eslint \"{demo,src,tests}/**/*\"",
"lint": "eslint \"{demo,src,tests}/**/*.{ts,vue}\"",
"postinstall": "node ./scripts/postinstall.js",
"changelog": "node ./scripts/changelog.js",
"release:prepare-packages": "node ./scripts/preparepackages.js",
Expand Down
11 changes: 3 additions & 8 deletions src/ckeditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@ import {
onBeforeUnmount
} from 'vue';
import type { Editor, EditorConfig, EventInfo } from 'ckeditor5';
import type { Props, ExtractEditorType } from './types.js';
type EditorType = TEditor extends { create( ...args: any[] ): Promise<infer E> } ? E : never;
type EditorType = ExtractEditorType<TEditor>;
defineOptions( {
name: 'CKEditor'
} );
const model = defineModel( 'modelValue', { type: String, default: '' } );
const props = withDefaults( defineProps<{
editor: TEditor;
config?: EditorConfig;
tagName?: string;
disabled?: boolean;
disableTwoWayDataBinding?: boolean;
}>(), {
const props = withDefaults( defineProps<Props<TEditor>>(), {
config: () => ( {} ),
tagName: 'div',
disabled: false,
Expand Down
32 changes: 32 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

import type { EditorConfig } from 'ckeditor5';

/**
* This file contains types for the CKEditor 5 Vue component.
* These types were moved to a separate file, because the `vue-tsc`
* package couldn't generate the correct types for the component
* when the types were in the component file. This is a workaround
* that may be fixed in the next versions of `vue-tsc`.
*/

/**
* The props accepted by the `<ckeditor>` component.
*/
export interface Props<TEditor> {
editor: TEditor;
config?: EditorConfig;
tagName?: string;
disabled?: boolean;
disableTwoWayDataBinding?: boolean;
}

/**
* The editor type extracted from the editor instance type.
*/
export type ExtractEditorType<TEditor> = TEditor extends { create( ...args: Array<any> ): Promise<infer E> }
? E
: never;
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"declaration": true,
"declarationDir": "./dist"
},
"include": ["src/plugin.ts"]
"include": [
"src"
]
}

0 comments on commit e2a9bbc

Please sign in to comment.