Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor Instance config Interface #285

Merged
merged 7 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 26 additions & 46 deletions build/codex-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/codex-editor.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/codex.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export default class CodexEditor {
this[method] = methods[method];
}

delete this.moduleInstances; // todo Is it necessary?
// todo Is it necessary?
delete this.moduleInstances;
})
.then(() => {
console.log('CodeX Editor is ready!');
Expand Down
26 changes: 13 additions & 13 deletions src/components/__module.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import IEditor from './interfaces/editor';
import IEditorConfig from './interfaces/editor-config';
import IModuleConfig from './interfaces/module-config';

/**
* @abstract
* @class Module
* @classdesc All modules inherits from this class.
*
* @typedef {Module} Module
* @property {Object} config - Editor user settings
* @property {Object} Editor - List of Editor modules
* @property {IEditorConfig} Editor - List of Editor modules
*/
export default class Module {

/**
* Editor modules list
* @type {EditorComponents}
* @type {IEditor}
*/
protected Editor: any = null;
protected Editor: IEditor;

/**
* Editor configuration object
* @type {EditorConfig}
* @type {IEditorConfig}
*/
protected config: any = {};
protected config: IEditorConfig;

/**
* @constructor
*
* @param {EditorConfig} config
* @param {IModuleConfig}
*/
constructor({config}) {

constructor({config}: IModuleConfig) {
if (new.target === Module) {
throw new TypeError('Constructors for abstract class Module are not allowed.');
}

this.config = config;
}

/**
* Editor modules setter
*
* @param Editor
* @param Editor.modules {@link CodexEditor#moduleInstances}
* @param Editor.config {@link CodexEditor#configuration}
* @param {IEditor} Editor
*/
set state(Editor) {
this.Editor = Editor;
Expand Down
2 changes: 1 addition & 1 deletion src/components/interfaces/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IInputOutputData from "./input-output-data";
import IInputOutputData from './input-output-data';

/**
* CodeX Editor Public API
Expand Down
63 changes: 63 additions & 0 deletions src/components/interfaces/block-tool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import IEditorConfig from "./editor-config";

/**
* Describe Block Tool object
* @see {@link docs/tools.md}
*/
export interface IBlockTool {

/**
* Should this tools be displayed at the Editor's Toolbox
* @return {boolean}
*/
displayInToolbox(): boolean;

/**
* Class for the Toolbox icon
* @return {string}
*/
iconClassName(): string;

/**
* Create Block's settings block
* @return {HTMLElement}
*/
makeSettings(): HTMLElement;

/**
* Return Tool's main block-wrapper
* @return {HTMLElement}
*/
render(): HTMLElement;

/**
* Process Tool's element in DOM and return raw data
* @param {HTMLElement} block - element created by {@link IBlockTool#render} function
* @return {IBlockToolData}
*/
save(block: HTMLElement): IBlockToolData;

/**
* Method that specified how to merge two Text blocks.
* Called by CodeX Editor by backspace at the beginning of the Block
* @param {IBlockToolData} blockData
*/
merge(blockData: IBlockToolData): void;

/**
* Validate Block's data
* @param {IBlockToolData} blockData
* @return {boolean}
*/
validate(blockData: IBlockToolData): boolean;
}

/**
* Object returned by Tool's {@link IBlockTool#save} method
*/
export interface IBlockToolData {}

/**
* Object passed to the Tool's constructor by {@link IEditorConfig#toolsConfig}
*/
export interface IBlockToolConfig {}
52 changes: 52 additions & 0 deletions src/components/interfaces/editor-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {IBlockTool} from './block-tool';
import {IBlockToolConfig} from './block-tool';
import ISanitizerConfig from './sanitizer-config';

/**
* Editor Instance config
*/
export default interface IEditorConfig {

/**
* Element to append Editor
*/
holderId: string;

/**
* Blocks list in JSON-format
*/
data: IBlockToolConfig[];

/**
* Map of used Tools
*/
tools: {[toolName: string]: IBlockTool};

/**
* Tools configuration
* @see {@link tools#ToolConfig}
*/
toolsConfig: {[toolName: string]: IBlockToolConfig};

/**
* This Tool will be added by default
* Name should be equal a one Tool's key of Editor's Tools
*/
initialBlock: string;

/**
* First Block placeholder
*/
placeholder: string;

/**
* Define tags not to be stripped off while pasting
* @see {@link sanitizer}
*/
sanitizer: ISanitizerConfig;

/**
* Do not show toolbar
*/
hideToolbar: boolean;
}
Loading