Skip to content

Commit

Permalink
Merge pull request #40 from Sozialarchiv/ts
Browse files Browse the repository at this point in the history
To typescript migrated
  • Loading branch information
neSpecc authored Aug 17, 2024
2 parents 909a1f5 + f4fd816 commit 95a5eb9
Show file tree
Hide file tree
Showing 5 changed files with 981 additions and 201 deletions.
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/delimiter",
"version": "1.4.1",
"version": "1.4.2",
"keywords": [
"codex editor",
"delimiter",
Expand All @@ -15,10 +15,12 @@
],
"main": "./dist/delimiter.umd.js",
"module": "./dist/delimiter.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/delimiter.mjs",
"require": "./dist/delimiter.umd.js"
"require": "./dist/delimiter.umd.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
Expand All @@ -30,10 +32,13 @@
"email": "team@ifmo.su"
},
"devDependencies": {
"vite": "^4.5.0",
"vite-plugin-css-injected-by-js": "^3.3.0"
"vite": "^5.4.1",
"vite-plugin-css-injected-by-js": "^3.5.1",
"vite-plugin-dts": "^4.0.3",
"@editorjs/editorjs": "^2.30.5",
"typescript": "^5.5.4"
},
"dependencies": {
"@codexteam/icons": "^0.0.5"
"@codexteam/icons": "^0.3.2"
}
}
40 changes: 25 additions & 15 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Build styles
*/
import './index.css';

import {API, BlockTool, BlockToolConstructorOptions, BlockToolData, ToolboxConfig, PasteConfig, PasteEvent} from "@editorjs/editorjs";
import { IconDelimiter } from '@codexteam/icons'

/**
Expand All @@ -18,24 +18,35 @@ import { IconDelimiter } from '@codexteam/icons'
* @typedef {Object} DelimiterData
* @description Tool's input and output data format
*/
export default class Delimiter {
export default class Delimiter implements BlockTool {

/**
* Notify core that read-only mode is supported
* @return {boolean}
*/
static get isReadOnlySupported() {
static get isReadOnlySupported(): boolean {
return true;
}

/**
* Allow Tool to have no content
* @return {boolean}
*/
static get contentless() {
static get contentless(): boolean {
return true;
}

private api: API

private _CSS: {
block: string
wrapper: string
}

private data: BlockToolData

private _element: HTMLDivElement

/**
* Render plugin`s main Element and fill it with saved data
*
Expand All @@ -44,27 +55,26 @@ export default class Delimiter {
* config - user config for Tool
* api - Editor.js API
*/
constructor({data, config, api}) {
constructor({data, config, api}: BlockToolConstructorOptions) {
this.api = api;

this._CSS = {
block: this.api.styles.block,
wrapper: 'ce-delimiter'
};

this._data = {};
this._element = this.drawView();

this.data = data;
}

/**
* Create Tool's view
* @return {HTMLElement}
* @return {HTMLDivElement}
* @private
*/
drawView() {
let div = document.createElement('DIV');
drawView(): HTMLDivElement {
let div = document.createElement('div');

div.classList.add(this._CSS.wrapper, this._CSS.block);

Expand All @@ -76,7 +86,7 @@ export default class Delimiter {
* @returns {HTMLDivElement}
* @public
*/
render() {
render(): HTMLDivElement {
return this._element;
}

Expand All @@ -86,7 +96,7 @@ export default class Delimiter {
* @returns {DelimiterData} - saved data
* @public
*/
save(toolsContent) {
save(toolsContent: HTMLElement): BlockToolData {
return {};
}

Expand All @@ -97,19 +107,19 @@ export default class Delimiter {
*
* @return {{icon: string, title: string}}
*/
static get toolbox() {
static get toolbox(): ToolboxConfig {
return {
icon: IconDelimiter,
title: 'Delimiter'
};
}

/**
* Delimiter onPaste configuration
*
* @public
*/
static get pasteConfig() {
static get pasteConfig(): PasteConfig {
return { tags: ['HR'] };
}

Expand All @@ -118,7 +128,7 @@ export default class Delimiter {
*
* @param {PasteEvent} event - event with pasted data
*/
onPaste(event) {
onPaste(event: PasteEvent): void {
this.data = {};
}
}
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"include": ["src/**/*"],
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist",
"strict": true,
"moduleResolution": "nodenext"
}
}
11 changes: 9 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "path";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import * as pkg from "./package.json";
import dts from "vite-plugin-dts";

const NODE_ENV = process.argv.mode || "development";
const VERSION = pkg.version;
Expand All @@ -9,7 +10,7 @@ export default {
build: {
copyPublicDir: false,
lib: {
entry: path.resolve(__dirname, "src", "index.js"),
entry: path.resolve(__dirname, "src", "index.ts"),
name: "Delimiter",
fileName: "delimiter",
},
Expand All @@ -19,5 +20,11 @@ export default {
VERSION: JSON.stringify(VERSION),
},

plugins: [cssInjectedByJsPlugin()],
plugins: [
cssInjectedByJsPlugin(),
dts({
//insertTypesEntry: true,
tsconfigPath: './tsconfig.json'
}),
],
};
Loading

0 comments on commit 95a5eb9

Please sign in to comment.