Skip to content

Conversation

@arenac
Copy link

@arenac arenac commented Jun 10, 2024

Adding Typescript support to improve developement experience.
And generating types declarion during build, to be published and also to improve development experirce for the library users.

Copy link
Contributor

@neSpecc neSpecc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

src/index.ts Outdated
* @property {boolean} checked - is the item checked
*/
import './polyfills.js';
interface ChecklistItem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets export it

src/index.ts Outdated
* @typedef {object} ChecklistData
* @property {ChecklistItem[]} items - checklist elements
*/
interface ChecklistData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this

package.json Outdated
"scripts": {
"dev": "vite",
"build": "vite build"
"build": "tsc && vite build"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite will automatically compile the .ts file, isn't it?

Comment on lines 34 to 37
private _elements: { wrapper: HTMLElement | null; items: HTMLElement[] };
private readOnly: boolean;
private api: any;
private data: ChecklistData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, add docs for all interfaces and properties

src/index.ts Outdated
Comment on lines 7 to 9
* @typedef {object} ChecklistItem
* @property {string} text - item label
* @property {boolean} checked - is the item checked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move docs to each property, please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual. Typedef is not needed anymore, use comments near properties instead

src/index.ts Outdated

const items = this.items;
const currentItem = document.activeElement.closest(`.${this.CSS.item}`);
const currentItem = document.activeElement?.closest(`.${this.CSS.item}`) as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

backspace(event) {
const currentItem = event.target.closest(`.${this.CSS.item}`);
backspace(event: KeyboardEvent): void {
const currentItem = (event.target as HTMLElement).closest(`.${this.CSS.item}`) as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual

}

const selection = window.getSelection();
const selection = window.getSelection() as Selection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

src/utils.ts Outdated
Comment on lines 1 to 5
/**
* Remove and return HTML content after carer position in current input
*
* @returns {DocumentFragment} extracted HTML nodes
*/
export function extractContentAfterCaret() {
const input = document.activeElement;
const selection = window.getSelection();
* Remove and return HTML content after carer position in current input
*
* @returns {DocumentFragment} extracted HTML nodes
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad "*" aligning

Comment on lines +7 to +8
const input = document.activeElement as HTMLElement;
const selection = window.getSelection() as Selection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected casting

@arenac arenac force-pushed the typescript-support branch 2 times, most recently from da57ad8 to 6d8a249 Compare June 17, 2024 20:31
@arenac arenac force-pushed the typescript-support branch from 6d8a249 to 9c848ec Compare June 17, 2024 20:33
@arenac
Copy link
Author

arenac commented Jun 17, 2024

@neSpecc thanks for the review so far. I pushed some udpates.

src/index.ts Outdated
Comment on lines 7 to 9
* @typedef {object} ChecklistItem
* @property {string} text - item label
* @property {boolean} checked - is the item checked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual. Typedef is not needed anymore, use comments near properties instead

* @returns {{export: Function, import: Function}}
*/
static get conversionConfig() {
static get conversionConfig(): { export: (data: ChecklistData) => string; import: (str: string) => ChecklistData } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show me the error you got. I think, it should work fine. Maybe you need to make ChecklistData extend BlockToolData ?

src/index.ts Outdated
if (isLastItem) {
const currentItemText = getHTML(this.getItemInput(currentItem));
const isEmptyItem = currentItemText.length === 0;
if (isLastItem && currentItem) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change can break the logic. Its better to handle currentItem=undefined case separately above

backspace(event) {
const currentItem = event.target.closest(`.${this.CSS.item}`);
backspace(event: KeyboardEvent): void {
const currentItem = (event.target as HTMLElement).closest(`.${this.CSS.item}`) as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual

* Checklist Tool for the Editor.js 2.0
*/
export default class Checklist {
/** @private HTML nodes */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@private is not needed in typescript since you explicitly specify access modifier

{
"name": "@editorjs/checklist",
"version": "1.6.0",
"version": "1.7.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "1.7.0",
"version": "1.6.1",

* @property {boolean} checked - is the item checked
* CheckList constructor options
*/
export interface ChecklistOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use the BlockToolConstructorOptions the from editorjs package

* @returns {{icon: string, title: string}}
*/
static get toolbox() {
static get toolbox(): { icon: string; title: string } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static get toolbox(): { icon: string; title: string } {
static get toolbox(): ToolboxConfig {

/**
* Checklist Tool for the Editor.js 2.0
*/
export default class Checklist {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default class Checklist {
export default class Checklist implements BlockTool {

checkListItem.classList.toggle(this.CSS.itemChecked);
checkbox.classList.add(this.CSS.noHover);
checkbox.addEventListener('mouseleave', () => this.removeSpecialHoverBehavior(checkbox), { once: true });
toggleCheckbox(target: HTMLElement | null, event: MouseEvent): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why target has been added?

export function moveCaret(element: HTMLElement, toStart: boolean = false, offset?: number): void {
const range = document.createRange();
const selection = window.getSelection();
const selection = window.getSelection() as Selection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casting is not expected here, it can lead errors since there can be no selection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants