Skip to content

Commit 9432709

Browse files
authored
Merge pull request #311 from ckeditor/ck/narrow-cdn-config
Feature: Improve result type of `useCKEditorCloud` to make `CKEditorPremiumFeatures` and `CKBox` non-nullable when proper configuration is passed. Fix: Rename the `languages` configuration property to `translations` in `useCKEditorCloud`.
2 parents 289a5ac + 5a14cc2 commit 9432709

8 files changed

+120
-18
lines changed

.circleci/config.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ commands:
5959
name: Prepare environment variables
6060
command: |
6161
#!/bin/bash
62-
62+
6363
# Non-secret environment variables needed for the pipeline scripts.
6464
CKE5_GITHUB_ORGANIZATION="ckeditor"
6565
CKE5_GITHUB_REPOSITORY="ckeditor5-vue"
6666
CKE5_CIRCLE_APPROVAL_JOB_NAME="release_approval"
6767
CKE5_GITHUB_RELEASE_BRANCH="master"
68-
68+
6969
echo export CKE5_CIRCLE_APPROVAL_JOB_NAME=$CKE5_CIRCLE_APPROVAL_JOB_NAME >> $BASH_ENV
7070
echo export CKE5_GITHUB_RELEASE_BRANCH=$CKE5_GITHUB_RELEASE_BRANCH >> $BASH_ENV
7171
echo export CKE5_GITHUB_ORGANIZATION=$CKE5_GITHUB_ORGANIZATION >> $BASH_ENV
@@ -117,6 +117,9 @@ jobs:
117117
- run:
118118
name: Build demo app
119119
command: yarn run build
120+
- run:
121+
name: Check types of tests
122+
command: yarn run test:check:types
120123
- run:
121124
name: Verify the code coverage
122125
command: |
@@ -205,13 +208,13 @@ jobs:
205208
name: Verify if a releaser triggered the job
206209
command: |
207210
#!/bin/bash
208-
211+
209212
# Do not fail if the Node script ends with non-zero exit code.
210213
set +e
211-
214+
212215
yarn ckeditor5-dev-ci-is-job-triggered-by-member
213216
EXIT_CODE=$( echo $? )
214-
217+
215218
if [ ${EXIT_CODE} -ne 0 ];
216219
then
217220
echo "Aborting the release due to failed verification of the approver (no rights to release)."

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"dependencies": {
3333
"lodash-es": "^4.17.21",
34-
"@ckeditor/ckeditor5-integrations-common": "^1.0.0"
34+
"@ckeditor/ckeditor5-integrations-common": "^2.0.0"
3535
},
3636
"peerDependencies": {
3737
"ckeditor5": ">=42.0.0 || ^0.0.0-nightly",
@@ -82,6 +82,7 @@
8282
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
8383
"test": "vitest run --coverage",
8484
"test:watch": "vitest --ui --watch",
85+
"test:check:types": "tsc --noEmit -p ./tests/tsconfig.json",
8586
"lint": "eslint \"{demos,src,tests}/**/*.{ts,vue}\"",
8687
"postinstall": "node ./scripts/postinstall.js",
8788
"changelog": "node ./scripts/changelog.js",

src/useCKEditorCloud.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useAsync, type AsyncComposableResult } from './composables/useAsync';
88

99
import {
1010
loadCKEditorCloud,
11-
type CdnPluginsPacks,
1211
type CKEditorCloudConfig,
1312
type CKEditorCloudResult
1413
} from '@ckeditor/ckeditor5-integrations-common';
@@ -18,7 +17,7 @@ import {
1817
*
1918
* @param config The configuration of the CKEditor Cloud services.
2019
* @returns The result of the loaded CKEditor Cloud services.
21-
* @template A The type of the additional resources to load.
20+
* @template Config The type of the CKEditor Cloud configuration.
2221
* @experimental
2322
* @example
2423
* ```ts
@@ -35,11 +34,11 @@ import {
3534
* // ..
3635
* }
3736
*/
38-
export default function useCKEditorCloud<A extends CdnPluginsPacks>(
39-
config: MaybeRefOrGetter<CKEditorCloudConfig<A>>
40-
): AsyncComposableResult<CKEditorCloudResult<A>> {
37+
export default function useCKEditorCloud<Config extends CKEditorCloudConfig>(
38+
config: MaybeRefOrGetter<Config>
39+
): AsyncComposableResult<CKEditorCloudResult<Config>> {
4140
return useAsync(
42-
(): Promise<CKEditorCloudResult<A>> => loadCKEditorCloud(
41+
(): Promise<CKEditorCloudResult<Config>> => loadCKEditorCloud(
4342
toValue( config )
4443
)
4544
);

tests/ckeditor.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { nextTick } from 'vue';
77
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
88
import { mount } from '@vue/test-utils';
9-
import { Ckeditor } from '../src/plugin.ts';
9+
import { Ckeditor } from '../src/plugin';
1010
import {
1111
MockEditor,
1212
ModelDocument,

tests/globals.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
declare module '*.vue' {
7+
import type { DefineComponent } from 'vue';
8+
9+
const Component: DefineComponent<object, object, any>;
10+
11+
export default Component;
12+
}

tests/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"emitDeclarationOnly": false,
5+
"noImplicitAny": false
6+
},
7+
"include": [
8+
"./",
9+
"../src"
10+
]
11+
}

tests/useCKEditorCloud.test.ts

+77-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* For licensing, see LICENSE.md.
44
*/
55

6-
import { beforeEach, describe, it, vi, expect } from 'vitest';
6+
import { beforeEach, describe, it, vi, expect, expectTypeOf } from 'vitest';
77
import { flushPromises } from '@vue/test-utils';
88
import { ref } from 'vue';
99

@@ -53,4 +53,80 @@ describe( 'useCKEditorCloud', () => {
5353
expect( data.value?.CKEditorPremiumFeatures ).toBeDefined();
5454
} );
5555
} );
56+
57+
describe( 'typings', () => {
58+
it( 'should return non-nullable premium features entry type if premium is enabled', async () => {
59+
const { data } = useCKEditorCloud( {
60+
version: '43.0.0',
61+
premium: true
62+
} );
63+
await vi.waitFor( () => {
64+
expect( data.value?.CKEditor ).toBeDefined();
65+
} );
66+
67+
if ( data.value ) {
68+
expectTypeOf( data.value?.CKEditorPremiumFeatures ).not.toBeNullable();
69+
}
70+
} );
71+
72+
it( 'should return nullable premium features entry type if premium is not passed', async () => {
73+
const { data } = useCKEditorCloud( {
74+
version: '43.0.0'
75+
} );
76+
77+
await vi.waitFor( () => {
78+
expect( data.value?.CKEditor ).toBeDefined();
79+
} );
80+
81+
if ( data.value ) {
82+
expectTypeOf( data.value.CKEditorPremiumFeatures ).toBeNullable();
83+
}
84+
} );
85+
86+
it( 'should return nullable premium features entry type if premium is false', async () => {
87+
const { data } = useCKEditorCloud( {
88+
version: '43.0.0',
89+
premium: false
90+
} );
91+
92+
await vi.waitFor( () => {
93+
expect( data.value?.CKEditor ).toBeDefined();
94+
} );
95+
96+
if ( data.value ) {
97+
expectTypeOf( data.value.CKEditorPremiumFeatures ).toBeNullable();
98+
}
99+
} );
100+
101+
it( 'should return non-nullable ckbox entry type if ckbox enabled', async () => {
102+
const { data } = useCKEditorCloud( {
103+
version: '43.0.0',
104+
ckbox: {
105+
version: '2.5.1'
106+
}
107+
} );
108+
109+
await vi.waitFor( () => {
110+
expect( data.value?.CKEditor ).toBeDefined();
111+
} );
112+
113+
if ( data.value ) {
114+
expectTypeOf( data.value.CKBox ).not.toBeNullable();
115+
}
116+
} );
117+
118+
it( 'should return nullable ckbox entry type if ckbox not configured', async () => {
119+
const { data } = useCKEditorCloud( {
120+
version: '43.0.0'
121+
} );
122+
123+
await vi.waitFor( () => {
124+
expect( data.value?.CKEditor ).toBeDefined();
125+
} );
126+
127+
if ( data.value ) {
128+
expectTypeOf( data.value.CKBox ).toBeNullable();
129+
}
130+
} );
131+
} );
56132
} );

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,10 @@
11951195
"@ckeditor/ckeditor5-utils" "42.0.2"
11961196
ckeditor5 "42.0.2"
11971197

1198-
"@ckeditor/ckeditor5-integrations-common@^1.0.0":
1199-
version "1.0.0"
1200-
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-integrations-common/-/ckeditor5-integrations-common-1.0.0.tgz#f2f73509d029398929ee30da3ae23329de5a796a"
1201-
integrity sha512-HLToIJ7FAtKX0tu9GaGb1d39Kx0i0TFelAj2pQPiwPU/6DLgM5gi+m0WCZub+syruSonmZPONtWrrZZdUoDB/g==
1198+
"@ckeditor/ckeditor5-integrations-common@^2.0.0":
1199+
version "2.0.0"
1200+
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-integrations-common/-/ckeditor5-integrations-common-2.0.0.tgz#09ea8a6a6a3c01f601260a85d9af98ede78644cf"
1201+
integrity sha512-Gkt7tYVv168voQZFdN4PxVp6M5/ZgzIOrqI6uPRjuk73dYjdLCeotnEXYejE6cxyLi9m2UM2mvhXibOIKVcoPw==
12021202

12031203
"@ckeditor/ckeditor5-language@42.0.2":
12041204
version "42.0.2"

0 commit comments

Comments
 (0)