mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
Merge branch 'rewriting-version2.0' into module-tools-v2
# Conflicts: # src/codex.js # src/components/modules/tools.js
This commit is contained in:
commit
cd55c7360d
29 changed files with 10184 additions and 455 deletions
File diff suppressed because it is too large
Load diff
1
build/codex-editor.js.map
Normal file
1
build/codex-editor.js.map
Normal file
File diff suppressed because one or more lines are too long
5499
codex-editor.js
5499
codex-editor.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
32
src/codex.js
32
src/codex.js
|
|
@ -17,15 +17,16 @@
|
|||
* ...
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* All Editor components
|
||||
* Require Editor modules places in components/modules dir
|
||||
*/
|
||||
const modules = [
|
||||
require('./src/modules/dom'),
|
||||
require('./src/modules/core'),
|
||||
require('./src/modules/ui'),
|
||||
require('./src/modules/tools')
|
||||
];
|
||||
let modules = editorModules.map( module => {
|
||||
|
||||
return require('./components/modules/' + module );
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @class
|
||||
|
|
@ -52,8 +53,6 @@ module.exports = class CodexEditor {
|
|||
*/
|
||||
constructor(config) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Configuration object
|
||||
*/
|
||||
|
|
@ -139,9 +138,17 @@ module.exports = class CodexEditor {
|
|||
|
||||
modules.forEach( Module => {
|
||||
|
||||
this.moduleInstances[Module.name] = new Module({
|
||||
config : this.configuration
|
||||
});
|
||||
try {
|
||||
|
||||
this.moduleInstances[Module.name] = new Module({
|
||||
config : this.configuration
|
||||
});
|
||||
|
||||
} catch ( e ) {
|
||||
|
||||
console.log('Module %o skipped because %o', Module, e);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -200,7 +207,6 @@ module.exports = class CodexEditor {
|
|||
let prepareDecorator = module => module.prepare();
|
||||
|
||||
return Promise.resolve()
|
||||
.then(prepareDecorator(this.moduleInstances['core']))
|
||||
.then(prepareDecorator(this.moduleInstances['ui']))
|
||||
.then(prepareDecorator(this.moduleInstances['tools']))
|
||||
.catch(function (error) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
class Events {
|
||||
module.exports = class Events {
|
||||
|
||||
constructor() {
|
||||
|
||||
|
|
@ -32,4 +32,4 @@ class Events {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
|
@ -24,7 +24,9 @@
|
|||
module.exports = class Tools {
|
||||
|
||||
static get name() {
|
||||
|
||||
return 'tools';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +35,9 @@ module.exports = class Tools {
|
|||
* @param Editor.config {@link CodexEditor#configuration}
|
||||
*/
|
||||
set state(Editor) {
|
||||
|
||||
this.Editor = Editor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,11 +45,13 @@ module.exports = class Tools {
|
|||
* @return {ToolsConfig}
|
||||
*/
|
||||
get defaultConfig() {
|
||||
|
||||
return {
|
||||
iconClassName : 'default-icon',
|
||||
displayInToolbox : false,
|
||||
enableLineBreaks : false
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,10 +60,12 @@ module.exports = class Tools {
|
|||
* @param {ToolsConfig} config
|
||||
*/
|
||||
constructor(config) {
|
||||
|
||||
this.config = config;
|
||||
|
||||
this.availabPlugins = {};
|
||||
this.toolInstances = [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,7 +77,9 @@ module.exports = class Tools {
|
|||
let toolConfig = this.defaultConfig;
|
||||
|
||||
if (!this.config.hasOwnProperty('tools')) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,32 +90,41 @@ module.exports = class Tools {
|
|||
*/
|
||||
function waitNextToolPreparation(toolBindedPreparationFunction) {
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
toolBindedPreparationFunction()
|
||||
.then(resolve)
|
||||
.catch(function(error) {
|
||||
.catch(function (error) {
|
||||
|
||||
console.log('Plugin is not available because of ', error);
|
||||
|
||||
// anyway, go ahead even plugin is not available
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return new Promise(function(resolvePreparation, rejectPreparation) {
|
||||
return new Promise(function (resolvePreparation, rejectPreparation) {
|
||||
|
||||
let toolPreparationList = [];
|
||||
|
||||
for(let tool of this.config.tools) {
|
||||
|
||||
let toolName = tool.name;
|
||||
|
||||
if (toolName in this.config.toolsConfig) {
|
||||
|
||||
toolConfig = this.config.toolsConfig[toolName];
|
||||
|
||||
}
|
||||
|
||||
if (tool.prepare && typeof tool.prepare === 'function') {
|
||||
|
||||
toolPreparationList.push(tool.prepare.bind(toolConfig));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -117,14 +136,16 @@ module.exports = class Tools {
|
|||
|
||||
} else {
|
||||
|
||||
toolPreparationList.reduce(function(previousToolPrepared, currentToolReadyToPreparation, iteration) {
|
||||
toolPreparationList.reduce(function (previousToolPrepared, currentToolReadyToPreparation, iteration) {
|
||||
|
||||
return previousToolPrepared
|
||||
.then(() => waitNextToolPreparation(currentToolReadyToPreparation))
|
||||
.then(() => {
|
||||
|
||||
if (iteration == toolPreparationList.length - 1) {
|
||||
|
||||
resolvePreparation();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -159,7 +180,9 @@ module.exports = class Tools {
|
|||
* @return {Array}
|
||||
*/
|
||||
getTools() {
|
||||
|
||||
return this.toolInstances;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/**
|
||||
* Module UI
|
||||
*
|
||||
* @type {UI}
|
||||
|
|
@ -36,6 +36,20 @@ let CSS_ = {
|
|||
editorZone : 'ce-redactor'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* @classdesc Makes CodeX Editor UI:
|
||||
* <codex-editor>
|
||||
* <ce-redactor />
|
||||
* <ce-toolbar />
|
||||
* <ce-inline-toolbar />
|
||||
* </codex-editor>
|
||||
*
|
||||
* @property {EditorConfig} config - editor configuration {@link CodexEditor#configuration}
|
||||
* @property {Object} Editor - available editor modules {@link CodexEditor#moduleInstances}
|
||||
*/
|
||||
module.exports = class UI {
|
||||
|
||||
/**
|
||||
|
|
@ -46,26 +60,24 @@ module.exports = class UI {
|
|||
|
||||
return 'ui';
|
||||
|
||||
};
|
||||
|
||||
constructor(Editor) {
|
||||
|
||||
this.wrapper = null;
|
||||
|
||||
// this.Editor = Editor;
|
||||
//
|
||||
// this.modules = this.Editor.modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {EditorConfig} config
|
||||
*/
|
||||
constructor( config ) {
|
||||
|
||||
this.config = config;
|
||||
this.Editor = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Editor
|
||||
* @param Editor.modules {@link Tools#list}
|
||||
* @param Editor.config {@link CodexEditor#configuration}
|
||||
* @param Editor
|
||||
* Editor modules setter
|
||||
* @param {object} Editor - available editor modules
|
||||
*/
|
||||
set state(Editor) {
|
||||
|
||||
|
|
@ -80,12 +92,8 @@ module.exports = class UI {
|
|||
*/
|
||||
prepare() {
|
||||
|
||||
|
||||
|
||||
console.log('ui prepare fired');
|
||||
|
||||
this.wrapper = document.createElement('div');
|
||||
|
||||
return;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
|
@ -23,12 +23,28 @@ const VERSION = process.env.VERSION || pkg.version;
|
|||
var webpack = require('webpack');
|
||||
var ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
/**
|
||||
* Available CodeX Editor modules placed in components/modules folder
|
||||
* They will required automatically.
|
||||
* Folders and files starting with '_' will be skipped
|
||||
* @type {Array}
|
||||
*/
|
||||
var editorModules = fs.readdirSync('./src/components/modules').filter( name => /.js$/.test(name) && name.substring(0,1) !== '_' );
|
||||
|
||||
editorModules.forEach( name => {
|
||||
console.log('Require modules/' + name);
|
||||
});
|
||||
|
||||
|
||||
module.exports = {
|
||||
|
||||
entry: {
|
||||
'codex-editor': './codex'
|
||||
'codex-editor': './src/codex'
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'build'),
|
||||
filename: '[name].js',
|
||||
library: [ 'CodexEditor' ]
|
||||
},
|
||||
|
|
@ -58,7 +74,8 @@ module.exports = {
|
|||
/** Pass variables into modules */
|
||||
new webpack.DefinePlugin({
|
||||
NODE_ENV: JSON.stringify(NODE_ENV),
|
||||
VERSION: JSON.stringify(VERSION)
|
||||
VERSION: JSON.stringify(VERSION),
|
||||
editorModules: JSON.stringify(editorModules)
|
||||
}),
|
||||
|
||||
/** Минифицируем CSS и JS */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue