Conversation
src/index.ts
Outdated
| * @property {boolean} checked - is the item checked | ||
| */ | ||
| import './polyfills.js'; | ||
| interface ChecklistItem { |
src/index.ts
Outdated
| * @typedef {object} ChecklistData | ||
| * @property {ChecklistItem[]} items - checklist elements | ||
| */ | ||
| interface ChecklistData { |
package.json
Outdated
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "vite build" | ||
| "build": "tsc && vite build" |
There was a problem hiding this comment.
vite will automatically compile the .ts file, isn't it?
| private _elements: { wrapper: HTMLElement | null; items: HTMLElement[] }; | ||
| private readOnly: boolean; | ||
| private api: any; | ||
| private data: ChecklistData; |
There was a problem hiding this comment.
please, add docs for all interfaces and properties
src/index.ts
Outdated
| * @typedef {object} ChecklistItem | ||
| * @property {string} text - item label | ||
| * @property {boolean} checked - is the item checked |
There was a problem hiding this comment.
move docs to each property, please
There was a problem hiding this comment.
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; |
| 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; |
| } | ||
|
|
||
| const selection = window.getSelection(); | ||
| const selection = window.getSelection() as Selection; |
src/utils.ts
Outdated
| /** | ||
| * 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 | ||
| */ |
| const input = document.activeElement as HTMLElement; | ||
| const selection = window.getSelection() as Selection; |
da57ad8 to
6d8a249
Compare
6d8a249 to
9c848ec
Compare
|
@neSpecc thanks for the review so far. I pushed some udpates. |
src/index.ts
Outdated
| * @typedef {object} ChecklistItem | ||
| * @property {string} text - item label | ||
| * @property {boolean} checked - is the item checked |
There was a problem hiding this comment.
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 } { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
| * Checklist Tool for the Editor.js 2.0 | ||
| */ | ||
| export default class Checklist { | ||
| /** @private HTML nodes */ |
There was a problem hiding this comment.
@private is not needed in typescript since you explicitly specify access modifier
| { | ||
| "name": "@editorjs/checklist", | ||
| "version": "1.6.0", | ||
| "version": "1.7.0", |
There was a problem hiding this comment.
| "version": "1.7.0", | |
| "version": "1.6.1", |
| * @property {boolean} checked - is the item checked | ||
| * CheckList constructor options | ||
| */ | ||
| export interface ChecklistOptions { |
There was a problem hiding this comment.
lets use the BlockToolConstructorOptions the from editorjs package
| * @returns {{icon: string, title: string}} | ||
| */ | ||
| static get toolbox() { | ||
| static get toolbox(): { icon: string; title: string } { |
There was a problem hiding this comment.
| static get toolbox(): { icon: string; title: string } { | |
| static get toolbox(): ToolboxConfig { |
| /** | ||
| * Checklist Tool for the Editor.js 2.0 | ||
| */ | ||
| export default class Checklist { |
There was a problem hiding this comment.
| 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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
casting is not expected here, it can lead errors since there can be no selection
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.