Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite ckeditor5-word-count to TypeScript. #13055

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ packages/ckeditor5-editor-inline/src/**/*.js
packages/ckeditor5-editor-balloon/src/**/*.js
packages/ckeditor5-editor-decoupled/src/**/*.js
packages/ckeditor5-essentials/src/**/*.js
packages/ckeditor5-word-count/src/**/*.js
packages/*/src/**/*.d.ts
src/**/*.js
src/**/*.d.ts
1 change: 1 addition & 0 deletions packages/ckeditor5-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export { default as DocumentFragment } from './model/documentfragment';
export { default as History } from './model/history';
export { default as Text } from './model/text';
export type { default as Batch } from './model/batch';
export type { default as Item } from './model/item';
export type { default as Node } from './model/node';
export type { default as Schema } from './model/schema';
export type { default as Selection } from './model/selection';
Expand Down
10 changes: 7 additions & 3 deletions packages/ckeditor5-word-count/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ckeditor5-plugin",
"ckeditor5-dll"
],
"main": "src/index.js",
"main": "src/index.ts",
"dependencies": {
"lodash-es": "^4.17.15",
"ckeditor5": "^35.3.2"
Expand All @@ -30,6 +30,7 @@
"@ckeditor/ckeditor5-table": "^35.3.2",
"@ckeditor/ckeditor5-theme-lark": "^35.3.2",
"@ckeditor/ckeditor5-utils": "^35.3.2",
"typescript": "^4.8.4",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
},
Expand All @@ -48,13 +49,16 @@
},
"files": [
"lang",
"src",
"src/**/*.js",
"src/**/*.d.ts",
"theme",
"build",
"ckeditor5-metadata.json",
"CHANGELOG.md"
],
"scripts": {
"dll:build": "webpack"
"dll:build": "webpack",
"build": "tsc -p ./tsconfig.release.json",
"postversion": "npm run build"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @module word-count
*/

export { default as WordCount } from './wordcount';
export { default as WordCount, type WordCountUpdateEvent } from './wordcount';
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
* @module word-count/utils
*/

import type { Element, Item } from 'ckeditor5/src/engine';

/**
* Returns a plain text representation of an element and its children.
*
* @param {module:engine/model/element~Element} element
* @returns {String} Plain text representing the model's data.
* @returns Plain text representing the model's data.
*/
export function modelElementToPlainText( element ) {
if ( element.is( '$text' ) || element.is( '$textProxy' ) ) {
return element.data;
export function modelElementToPlainText( item: Item ): string {
if ( item.is( '$text' ) || item.is( '$textProxy' ) ) {
return item.data;
}

const element = item as Element;
let text = '';
let prev = null;

Expand Down
Loading