Skip to content

Commit

Permalink
Merge pull request #13055 from ckeditor/ck/13036-ts-word-count
Browse files Browse the repository at this point in the history
Other (word-count): Rewrite ckeditor5-word-count to TypeScript. Closes #13036.
  • Loading branch information
arkflpc authored Dec 14, 2022
2 parents 26c2808 + d7ad509 commit 4627852
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 398 deletions.
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.4.0"
Expand All @@ -30,6 +30,7 @@
"@ckeditor/ckeditor5-table": "^35.4.0",
"@ckeditor/ckeditor5-theme-lark": "^35.4.0",
"@ckeditor/ckeditor5-utils": "^35.4.0",
"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

0 comments on commit 4627852

Please sign in to comment.