Skip to content

Commit

Permalink
Try create extra plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Dec 11, 2019
1 parent 7fb40ad commit dd6d589
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 20 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { IJodit } from "./src/types/jodit"
declare var Jodit: IJodit;
5 changes: 5 additions & 0 deletions make.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
paths: [
'./plugins/emoji/',
]
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"newversion": "npm test && npm version patch --no-git-tag-version && npm run build && npm run newversiongit && npm publish ./",
"newversiongit": "git add --all && git commit -m \"New version $npm_package_version. Read more https://github.com/xdan/jodit/releases/tag/$npm_package_version \" && git tag $npm_package_version && git push --tags origin HEAD:master",
"start": "node server.js",
"clean": "rm -f build/*",
"clean": "rm -rf build/*",
"build": "npm run clean && npm run build-es5 && npm run build-es18 && npm run build-no-uglify-es5 && npm run build-no-uglify-es18",
"build-es5": "webpack --progress --mode production --es es5 --uglify true",
"build-es18": "webpack --progress --mode production --es es2018 --uglify true",
Expand Down
3 changes: 3 additions & 0 deletions plugins/emoji/emoji.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.jodit_emoji {
color: red;
}
24 changes: 24 additions & 0 deletions plugins/emoji/emoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

// Config.prototype.controls.emoji = {
// icon: 'plugins/emoji/icon.svg',
// tooltip: 'Insert Emoji'
// } as IControlType;

/**
* Support emoji
*/
Jodit.plugins.emoji = class emoji {
afterInit(editor: any) {
// const buttons = editor.options.buttons;
//
// if (!buttons.includes('emoji')) {
// buttons.push('emoji');
// }
//
// editor.options.buttons = buttons;
}

beforeDestruct(editor: any) {

}
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const esFilter = (key: string): boolean => key !== '__esModule';
Object.keys(Icons)
.filter(esFilter)
.forEach((key: string) => {
ToolbarIcon.icons[key.replace('_', '-')] = (Icons as any)[key];
ToolbarIcon.setIcon(key.replace('_', '-'), (Icons as any)[key]);
});

// Modules
Expand Down
33 changes: 25 additions & 8 deletions src/modules/toolbar/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
import { IDictionary } from '../../types';

export class ToolbarIcon {
static icons: IDictionary<string> = {};
private static icons: IDictionary<string> = {};

private static get(name: string): string | undefined {
return ToolbarIcon.icons[name] ||
ToolbarIcon.icons[name.replace(/-/g, '_')] ||
ToolbarIcon.icons[name.toLowerCase()];
}

/**
* Check if icon exist in store
* @param name
*/
static exists(name: string): boolean {
return ToolbarIcon.icons[name] !== undefined;
return this.get(name) !== undefined;
}

/**
Expand All @@ -26,12 +36,19 @@ export class ToolbarIcon {
name: string,
defaultValue: string = '<span></span>'
): string {
return this.get(name) || defaultValue;
}

const icon =
ToolbarIcon.icons[name] ||
ToolbarIcon.icons[name.replace(/-/g, '_')] ||
ToolbarIcon.icons[name.toLowerCase()];

return icon || defaultValue;
/**
* Set SVG in store
*
* @param name
* @param value
*/
static setIcon(
name: string,
value: string
): void {
this.icons[name.replace('_', '-')] = value;
}
}
25 changes: 25 additions & 0 deletions src/utils/create-entries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require('path');
const fs = require('fs');

function createEntries(directory) {
const rootPath = path.resolve(process.cwd());
const fullPath = path.resolve(directory);
const files = fs.readdirSync(fullPath);

return files.reduce((entries, file) => {
let filename = path.join(fullPath, file);

if (fs.lstatSync(filename).isFile()) {
filename = filename.replace(rootPath, '.');
entries[filename.replace(/\.ts$/, '')] = filename;
} else {
Object.assign(entries, createEntries(filename))
}

return entries;
}, {})
}

module.exports = {
createEntries
};
15 changes: 15 additions & 0 deletions src/utils/svg-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
module.exports = function(content) {
this.cacheable && this.cacheable();
this.value = content;
return "module.exports = " + JSON.stringify(
content
.replace(/[\n\t]+/g, '')
.replace(/[\s]+/g, ' ')
);
};

module.exports.seperable = true;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
},

"typeRoots": ["./node_modules/@types/"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "build"]
}
40 changes: 31 additions & 9 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MinimizeJSPlugin = require('terser-webpack-plugin');

const pkg = require('./package.json');
const make = require('./make.js');
const { createEntries } = require('./src/utils/create-entries.js');

const banner = `/*!
${pkg.name} - ${pkg.description}
Expand All @@ -31,7 +33,7 @@ module.exports = (env, argv) => {

console.warn('ES mode: ' + ES);

const filename = 'jodit' + ((ES === 'es5' || isTest) ? '' : '.' + ES) + (uglify ? '.min' : '');
const filename = (name) => name + ((ES === 'es5' || isTest) ? '' : '.' + ES) + (uglify ? '.min' : '');

const css_loaders = [
(debug || isTest) ? 'style-loader' : MiniCssExtractPlugin.loader,
Expand Down Expand Up @@ -68,9 +70,10 @@ module.exports = (env, argv) => {

devtool: debug ? 'inline-sourcemap' : false,

entry: debug
? ['webpack-hot-middleware/client', './src/index']
: './src/index',
entry: {
jodit: (debug ? ['webpack-hot-middleware/client', './src/index'] : ['./src/index']),
...make.paths.reduce((entm, file) => ({...entm, ...createEntries(file)}), {})
},

resolve: {
extensions: ['.ts', '.d.ts', '.js', '.json', '.less', '.svg']
Expand Down Expand Up @@ -115,9 +118,9 @@ module.exports = (env, argv) => {
]
},

output: {
output: {
path: path.join(__dirname, 'build'),
filename: filename + '.js',
filename: filename('[name]') + '.js',
publicPath: '/build/',
libraryTarget: 'umd'
},
Expand All @@ -128,6 +131,23 @@ module.exports = (env, argv) => {
test: /\.less$/,
use: css_loaders
},
{
test: /\.(ts)$/,
loader: 'ts-loader',
options: {
transpileOnly: uglify,
compilerOptions: {
target: ES
}
},
include: path.resolve('../'),
exclude: [
path.resolve('src/'),
path.resolve('node_modules/'),
path.resolve('examples/'),
path.resolve('test/'),
]
},
{
test: /\.(ts)$/,
use: [
Expand All @@ -148,14 +168,16 @@ module.exports = (env, argv) => {
}
},
exclude: [
/(node_modules|bower_components)/,
/(node_modules)/,
/langs\/[a-z]{2}\.ts/,
/langs\/[a-z]{2}_[a-z]{2}\.ts/,
]
},
{
test: /\.svg$/i,
use: 'raw-loader'
use: {
loader: path.resolve('src/utils/svg-loader.js')
}
}
]
},
Expand Down Expand Up @@ -189,7 +211,7 @@ module.exports = (env, argv) => {
case 'production':
config.plugins.push(
new MiniCssExtractPlugin({
filename: filename + '.css'
filename: filename('[name]') + '.css'
})
);

Expand Down

0 comments on commit dd6d589

Please sign in to comment.